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 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. user_media: Joi.string(),
  22. user_type: Joi.any(),
  23. user: Joi.object()
  24. }),
  25. )
  26. ),
  27. error: errorSchema.single
  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, 'participant', false)
  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: apiSchema.single.append({
  77. data: responseSchemas.response,
  78. }),
  79. 409: apiSchema.single.append({
  80. data: responseSchemas.error,
  81. })
  82. },
  83. },
  84. },
  85. }