| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict'
-
- const Joi = require('joi')
-
- const pluginConfig = {
- handlerType: 'matchque',
- docs: {
- description: 'inserts scored matches',
- notes: 'Waits for Scoring Service, and inserts any that does not exist in MatchQue Table',
- },
- }
-
- const validators = {
- // /** Validate the header (cookie check) */
- // // headers: true,
-
- // /** Validate the route params (/active/{thing}) */
- params: Joi.object({ profile_id: Joi.number() }),
-
- // /** Validate the route query (/active/{thing}?limit=10&offset=10) */
- // // query: true,
-
- // /** Validate the incoming payload (POST method) */
-
- payload: Joi.object({
- maxDistance: Joi.number().required(),
- distanceUnit: Joi.string().required(),
- }),
- }
-
- module.exports = {
- method: 'POST',
- path: '/{profile_id}/matches',
- options: {
- ...pluginConfig.docs,
- tags: ['api'],
- /** Protect this route with authentication? */
- auth: false,
- handler: async function (request, h) {
- const { profile_id } = request.params
- const { maxDistance, distanceUnit } = request.payload
- const { matchQueService, profileService } =
- request.server.services()
- // get results back from profileServices.scoreProfilesFor(profile_id, maxDistance, distanceUnit)
- const potentials = await profileService.scoreProfilesFor(
- profile_id,
- maxDistance,
- distanceUnit,
- )
- let potentialProfileIds = potentials.map(
- potential => potential.profile_id,
- )
- potentialProfileIds = [...new Set(potentialProfileIds)]
-
- await matchQueService.insertScoredProfilesIntoMatchQue(
- profile_id,
- potentialProfileIds,
- )
-
- return matchQueService.getPotentials(profile_id)
- },
- /** Validate based on validators object */
- validate: {
- ...validators,
- failAction: 'log',
- },
-
- // couldn't get validate server response working...
-
- /** Validate the server response */
- // response: {
- // schema: Joi.object({
- // ok: Joi.bool(),
- // handler: Joi.string(),
- // data: Joi.object(),
- // }),
- // },
- },
- }
|