'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}/status', options: { ...pluginConfig.docs.get, tags: ['api'], auth: 'default_jwt', handler: async function (request, h) { try { const { userService } = request.services() const userId = request.params.userId const status = await userService.getStatus(userId, request.server.app.loggedInUsers) 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', }, }, }