Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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(),
  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 { profileService } = request.services()
  27. const postMatchYins = await profileService.calcMatches()
  28. try {
  29. if (!postMatchYins) {
  30. throw new RangeError('Unable to match profiles')
  31. }
  32. return h
  33. .response({
  34. ok: true,
  35. handler: pluginConfig.handlerType,
  36. data: postMatchYins,
  37. })
  38. .code(200)
  39. } catch (err) {
  40. return h
  41. .response({
  42. ok: false,
  43. handler: pluginConfig.handlerType,
  44. data: { error: `${err}` },
  45. })
  46. .code(409)
  47. }
  48. },
  49. /** Validate based on validators object */
  50. validate: {
  51. ...validators,
  52. failAction: 'log',
  53. },
  54. /** Validate the server response */
  55. response: {
  56. status: {
  57. 200: Joi.object({
  58. ok: Joi.bool(),
  59. handler: Joi.string(),
  60. data: responseSchemas.response,
  61. }),
  62. 409: Joi.object({
  63. ok: Joi.bool(),
  64. handler: Joi.string(),
  65. data: responseSchemas.error,
  66. }),
  67. },
  68. },
  69. },
  70. }