Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'profile',
  5. docs: {
  6. description: 'Returns previously scored profiles',
  7. notes: 'returns from the MatchQueue Table',
  8. },
  9. }
  10. const responseSchemas = {
  11. responses: Joi.array().items(
  12. Joi.alternatives().try(
  13. Joi.number(),
  14. Joi.object({
  15. profile_id: Joi.number(),
  16. user_id: Joi.number(),
  17. user_name: Joi.string(),
  18. responses: Joi.array().items(),
  19. user_media: Joi.string(),
  20. user_type: Joi.any(),
  21. user: Joi.object()
  22. }),
  23. )
  24. ),
  25. error: Joi.object({
  26. error: Joi.string(),
  27. }),
  28. }
  29. const validators = {
  30. params: Joi.object({ profile_id: Joi.number() }),
  31. query: Joi.object({ include_profile: Joi.bool() }),
  32. }
  33. module.exports = {
  34. method: 'GET',
  35. path: '/{profile_id}/queue',
  36. options: {
  37. ...pluginConfig.docs,
  38. tags: ['api'],
  39. /** Protect this route with authentication? */
  40. auth: false,
  41. cors: true,
  42. handler: async function (request, h) {
  43. const { profile_id } = request.params
  44. const { include_profile } = request.query
  45. const { profileService, matchQueueService } =
  46. request.server.services()
  47. const queue = await matchQueueService.getQueue(profile_id)
  48. const queueIds = queue.map(entry => entry.target_id)
  49. console.log('queueIds', queueIds)
  50. const res = {
  51. ok:true,
  52. handler: pluginConfig.handlerType,
  53. data: queueIds
  54. }
  55. // HELP: I think there's an issue here
  56. // queueIds spits out the queue profiles in the correct order
  57. // ~However~ when it goes through getProfilesFor
  58. // it comes back in literal database order regardless of is_deleted status
  59. console.log(
  60. 'include_profile results',
  61. await profileService.getProfilesFor(queueIds),
  62. )
  63. if(include_profile) {
  64. res.data = await profileService.getProfilesFor(queueIds)
  65. }
  66. try {
  67. return h.response(res).code(200)
  68. } catch (err) {
  69. return h.response({
  70. ok:false,
  71. handler: pluginConfig.handlerType,
  72. data: { error: `${err}`}
  73. }).code(409)
  74. }
  75. },
  76. /** Validate based on validators object */
  77. validate: {
  78. ...validators,
  79. failAction: 'log',
  80. },
  81. /** Validate the server response */
  82. response: {
  83. status: {
  84. 200: Joi.object({
  85. ok: Joi.bool(),
  86. handler: Joi.string(),
  87. data: responseSchemas.responses,
  88. }),
  89. 409: Joi.object({
  90. ok: Joi.bool(),
  91. handler: Joi.string(),
  92. data: responseSchemas.error,
  93. }),
  94. },
  95. },
  96. },
  97. }