Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

match.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: 'match',
  7. docs: {
  8. description: 'matches',
  9. notes: 'Match everyone',
  10. },
  11. }
  12. const validators = {}
  13. const responseSchemas = {
  14. response: Joi.array().items(Joi.object()),
  15. error: errorSchema.single
  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: apiSchema.single.append({
  60. data: responseSchemas.response,
  61. }),
  62. 409: apiSchema.single.append({
  63. data: responseSchemas.error,
  64. })
  65. },
  66. },
  67. },
  68. }