| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 'use strict'
-
- const Joi = require('joi')
- const apiSchema = require('../../schemas/api')
- const errorSchema = require('../../schemas/errors')
-
- const pluginConfig = {
- handlerType: 'match',
- docs: {
- description: 'matches',
- notes: 'Match everyone',
- },
- }
-
- const validators = {}
-
- const responseSchemas = {
- response: Joi.array().items(Joi.object()),
- error: errorSchema.single
- }
-
- module.exports = {
- method: 'GET',
- path: '/match',
- options: {
- ...pluginConfig.docs,
- tags: ['api'],
- /** Protect this route with authentication? */
- auth: false,
-
- handler: async function (request, h) {
- const { matchService, matchQueueService } =
- request.server.services()
- const allQueues = await matchQueueService.getAllQueues()
- const matched = await matchService.calcMatches(allQueues)
- try {
- if (!allQueues) {
- throw new RangeError('Unable to match profiles')
- }
-
- return h
- .response({
- ok: true,
- handler: pluginConfig.handlerType,
- data: matched,
- })
- .code(200)
- } catch (err) {
- return h
- .response({
- ok: false,
- handler: pluginConfig.handlerType,
- data: { error: `${err}` },
- })
- .code(409)
- }
- },
-
- /** Validate based on validators object */
- validate: {
- ...validators,
- failAction: 'log',
- },
-
- /** Validate the server response */
- response: {
- status: {
- 200: apiSchema.single.append({
- data: responseSchemas.response,
- }),
- 409: apiSchema.single.append({
- data: responseSchemas.error,
- })
- },
- },
- },
- }
|