| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 'use strict'
-
- const Joi = require('joi')
- const params = require('../../schemas/params')
-
- const pluginConfig = {
- handlerType: 'user',
- docs: {
- get: {
- description: 'Get user online status',
- notes: 'Returns a user online status by the id passed in the path',
- },
- }
- }
-
- const validators = {
- get: {
- params: params.userId,
- }
- }
-
- module.exports = {
- method: 'get',
- path: '/{id}',
- options: {
- ...pluginConfig.docs.get,
- tags: ['api'],
- auth: 'default_jwt',
- handler: async function (request, h) {
- try {
- // TODO write userService method to return a user's status given id
- const { userService } = request.services()
- const userId = request.params.userId
-
- const status = await userService.getStatus(userId)
-
- return {
- ok: true,
- handler: pluginConfig.handlerType,
- data: { status: status },
- }
- } catch (err) {
- return {
- ok: false,
- handler: pluginConfig.handlerType,
- data: { error: err },
- }
- }
- },
- validate: validators.get,
- response: {
- schema: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: validators.get.params,
- }).label('user_status_res'),
- failAction: 'log',
- },
- },
- }
|