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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if(include_profile) {
  56. res.data = await profileService.getProfilesFor(queueIds)
  57. }
  58. try {
  59. return h.response(res).code(200)
  60. } catch (err) {
  61. return h.response({
  62. ok:false,
  63. handler: pluginConfig.handlerType,
  64. data: { error: `${err}`}
  65. }).code(409)
  66. }
  67. },
  68. /** Validate based on validators object */
  69. validate: {
  70. ...validators,
  71. failAction: 'log',
  72. },
  73. /** Validate the server response */
  74. response: {
  75. status: {
  76. 200: Joi.object({
  77. ok: Joi.bool(),
  78. handler: Joi.string(),
  79. data: responseSchemas.responses,
  80. }),
  81. 409: Joi.object({
  82. ok: Joi.bool(),
  83. handler: Joi.string(),
  84. data: responseSchemas.error,
  85. }),
  86. },
  87. },
  88. },
  89. }