You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. responses: Joi.array().items(),
  18. user_type: Joi.any(),
  19. }),
  20. )
  21. ),
  22. error: Joi.object({
  23. error: Joi.string(),
  24. }),
  25. }
  26. const validators = {
  27. params: Joi.object({ profile_id: Joi.number() }),
  28. query: Joi.object({ include_profile: Joi.bool() }),
  29. }
  30. module.exports = {
  31. method: 'GET',
  32. path: '/{profile_id}/queue',
  33. options: {
  34. ...pluginConfig.docs,
  35. tags: ['api'],
  36. /** Protect this route with authentication? */
  37. auth: false,
  38. handler: async function (request, h) {
  39. const { profile_id } = request.params
  40. const { include_profile } = request.query
  41. const { profileService, matchQueueService } =
  42. request.server.services()
  43. const queue = await matchQueueService.getQueue(profile_id)
  44. const queueIds = queue.map(entry => entry.target_id)
  45. const res = {
  46. ok:true,
  47. handler: pluginConfig.handlerType,
  48. data: queueIds
  49. }
  50. if(include_profile) {
  51. res.data = await profileService.getProfilesFor(queueIds)
  52. }
  53. console.log(res.data)
  54. try {
  55. return h.response(res).code(200)
  56. } catch (err) {
  57. return h.response({
  58. ok:false,
  59. handler: pluginConfig.handlerType,
  60. data: { error: `${err}`}
  61. }).code(409)
  62. }
  63. },
  64. /** Validate based on validators object */
  65. validate: {
  66. ...validators,
  67. failAction: 'log',
  68. },
  69. /** Validate the server response */
  70. response: {
  71. status: {
  72. 200: Joi.object({
  73. ok: Joi.bool(),
  74. handler: Joi.string(),
  75. data: responseSchemas.responses,
  76. }),
  77. 409: Joi.object({
  78. ok: Joi.bool(),
  79. handler: Joi.string(),
  80. data: responseSchemas.error,
  81. }),
  82. },
  83. },
  84. },
  85. }