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

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