您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

queue.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: Joi.object({
  23. include_profile: Joi.bool(),
  24. limit: Joi.number(),
  25. offset: Joi.number(),
  26. }),
  27. }
  28. module.exports = {
  29. method: 'GET',
  30. path: '/{profile_id}/queue',
  31. options: {
  32. ...pluginConfig.docs,
  33. tags: ['api'],
  34. /** Protect this route with authentication? */
  35. auth: false,
  36. cors: true,
  37. handler: async function (request, h) {
  38. const { profile_id } = request.params
  39. const { limit, offset } = request.query
  40. const { profileService, matchQueueService } =
  41. request.server.services()
  42. const queue = await matchQueueService.getQueue(
  43. profile_id,
  44. limit,
  45. offset,
  46. )
  47. const queueIds = queue.map(entry => entry.target_id)
  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. try {
  57. return h
  58. .response({
  59. ok: true,
  60. handler: pluginConfig.handlerType,
  61. data: await profileService.getProfilesFor(
  62. queueIds,
  63. 'participant',
  64. ),
  65. })
  66. .code(200)
  67. } catch (err) {
  68. return h
  69. .response({
  70. ok: false,
  71. handler: pluginConfig.handlerType,
  72. data: { error: `${err}` },
  73. })
  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
  86. .append({
  87. data: responseSchemas.response,
  88. })
  89. .label('match_queue_res'),
  90. 409: apiSchema.single
  91. .append({
  92. data: responseSchemas.error,
  93. })
  94. .label('error_single_res'),
  95. },
  96. },
  97. },
  98. }