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.

match.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'match',
  5. docs: {
  6. description: 'matches',
  7. notes: 'Match everyone',
  8. },
  9. }
  10. const validators = {}
  11. const responseSchemas = {
  12. response: Joi.array().items(Joi.object()),
  13. error: Joi.object({
  14. error: Joi.string(),
  15. }),
  16. }
  17. module.exports = {
  18. method: 'GET',
  19. path: '/match',
  20. options: {
  21. ...pluginConfig.docs,
  22. tags: ['api'],
  23. /** Protect this route with authentication? */
  24. auth: false,
  25. handler: async function (request, h) {
  26. const { matchService, matchQueueService } =
  27. request.server.services()
  28. const allQueues = await matchQueueService.getAllQueues()
  29. const matched = await matchService.calcMatches(allQueues)
  30. try {
  31. if (!allQueues) {
  32. throw new RangeError('Unable to match profiles')
  33. }
  34. return h
  35. .response({
  36. ok: true,
  37. handler: pluginConfig.handlerType,
  38. data: matched,
  39. })
  40. .code(200)
  41. } catch (err) {
  42. return h
  43. .response({
  44. ok: false,
  45. handler: pluginConfig.handlerType,
  46. data: { error: `${err}` },
  47. })
  48. .code(409)
  49. }
  50. },
  51. /** Validate based on validators object */
  52. validate: {
  53. ...validators,
  54. failAction: 'log',
  55. },
  56. /** Validate the server response */
  57. response: {
  58. status: {
  59. 200: Joi.object({
  60. ok: Joi.bool(),
  61. handler: Joi.string(),
  62. data: responseSchemas.response,
  63. }),
  64. 409: Joi.object({
  65. ok: Joi.bool(),
  66. handler: Joi.string(),
  67. data: responseSchemas.error,
  68. }),
  69. },
  70. },
  71. },
  72. }