| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 'use strict'
-
- const Joi = require('joi')
-
- const pluginConfig = {
- handlerType: 'profile',
- docs: {
- description: 'Returns previously scored profiles',
- notes: 'returns from the MatchQueue Table',
- },
- }
-
- const responseSchemas = {
- responses: Joi.array().items(
- Joi.alternatives().try(
- Joi.number(),
- Joi.object({
- profile_id: Joi.number(),
- user_id: Joi.number(),
- user_name: Joi.string(),
- responses: Joi.array().items(),
- user_media: Joi.string(),
- user_type: Joi.any(),
- user: Joi.object()
- }),
- )
- ),
- error: Joi.object({
- error: Joi.string(),
- }),
- }
-
- const validators = {
- params: Joi.object({ profile_id: Joi.number() }),
- query: Joi.object({ include_profile: Joi.bool() }),
- }
-
- module.exports = {
- method: 'GET',
- path: '/{profile_id}/queue',
- options: {
- ...pluginConfig.docs,
- tags: ['api'],
- /** Protect this route with authentication? */
- auth: false,
- cors: true,
- handler: async function (request, h) {
- const { profile_id } = request.params
- const { include_profile } = request.query
- const { profileService, matchQueueService } =
- request.server.services()
-
- const queue = await matchQueueService.getQueue(profile_id)
- const queueIds = queue.map(entry => entry.target_id)
- // console.log('queueIds', queueIds)
- const res = {
- ok:true,
- handler: pluginConfig.handlerType,
- data: queueIds
- }
-
- if(include_profile) {
- res.data = await profileService.getProfilesFor(queueIds)
- }
- try {
- return h.response(res).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: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: responseSchemas.responses,
- }),
- 409: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: responseSchemas.error,
- }),
- },
- },
- },
- }
|