|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+'use strict'
|
|
|
2
|
+
|
|
|
3
|
+const Joi = require('joi')
|
|
|
4
|
+const params = require('../../schemas/params')
|
|
|
5
|
+
|
|
|
6
|
+const pluginConfig = {
|
|
|
7
|
+ handlerType: 'user',
|
|
|
8
|
+ docs: {
|
|
|
9
|
+ get: {
|
|
|
10
|
+ description: 'Get user online status',
|
|
|
11
|
+ notes: 'Returns a user online status by the id passed in the path',
|
|
|
12
|
+ },
|
|
|
13
|
+ }
|
|
|
14
|
+}
|
|
|
15
|
+
|
|
|
16
|
+const validators = {
|
|
|
17
|
+ get: {
|
|
|
18
|
+ params: params.userId,
|
|
|
19
|
+ }
|
|
|
20
|
+}
|
|
|
21
|
+
|
|
|
22
|
+module.exports = {
|
|
|
23
|
+ method: 'get',
|
|
|
24
|
+ path: '/{id}',
|
|
|
25
|
+ options: {
|
|
|
26
|
+ ...pluginConfig.docs.get,
|
|
|
27
|
+ tags: ['api'],
|
|
|
28
|
+ auth: 'default_jwt',
|
|
|
29
|
+ handler: async function (request, h) {
|
|
|
30
|
+ try {
|
|
|
31
|
+ // TODO write userService method to return a user's status given id
|
|
|
32
|
+ const { userService } = request.services()
|
|
|
33
|
+ const userId = request.params.userId
|
|
|
34
|
+
|
|
|
35
|
+ const status = await userService.getStatus(userId)
|
|
|
36
|
+
|
|
|
37
|
+ return {
|
|
|
38
|
+ ok: true,
|
|
|
39
|
+ handler: pluginConfig.handlerType,
|
|
|
40
|
+ data: { status: status },
|
|
|
41
|
+ }
|
|
|
42
|
+ } catch (err) {
|
|
|
43
|
+ return {
|
|
|
44
|
+ ok: false,
|
|
|
45
|
+ handler: pluginConfig.handlerType,
|
|
|
46
|
+ data: { error: err },
|
|
|
47
|
+ }
|
|
|
48
|
+ }
|
|
|
49
|
+ },
|
|
|
50
|
+ validate: validators.get,
|
|
|
51
|
+ response: {
|
|
|
52
|
+ schema: Joi.object({
|
|
|
53
|
+ ok: Joi.bool(),
|
|
|
54
|
+ handler: Joi.string(),
|
|
|
55
|
+ data: validators.get.params,
|
|
|
56
|
+ }).label('user_status_res'),
|
|
|
57
|
+ failAction: 'log',
|
|
|
58
|
+ },
|
|
|
59
|
+ },
|
|
|
60
|
+}
|