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

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