Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

queue.js 3.1KB

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