Просмотр исходного кода

:construction: online status endpoint just missing actual service

user-online-status
juancarbajal98 3 лет назад
Родитель
Сommit
4097459c70
3 измененных файлов: 66 добавлений и 0 удалений
  1. 2
    0
      backend/lib/plugins/user.js
  2. 60
    0
      backend/lib/routes/user/online-status.js
  3. 4
    0
      backend/lib/services/user.js

+ 2
- 0
backend/lib/plugins/user.js Просмотреть файл

@@ -13,6 +13,7 @@ const UserProfilesListRoute = require('../routes/user/list-profiles')
13 13
 const UserLoginRoute = require('../routes/user/login')
14 14
 const UserSignupRoute = require('../routes/user/signup')
15 15
 const UserPassword = require('../routes/user/authentication')
16
+const UserOnlineStatusRoute = require('../routes/user/online-status')
16 17
 
17 18
 const UserService = require('../services/user')
18 19
 const DisplayService = require('../services/display')
@@ -50,5 +51,6 @@ module.exports = {
50 51
         await server.route(UserProfileCreateRoute)
51 52
         await server.route(UserProfilesListRoute)
52 53
         await server.route(UserPassword)
54
+        await server.route(UserOnlineStatusRoute)
53 55
     },
54 56
 }

+ 60
- 0
backend/lib/routes/user/online-status.js Просмотреть файл

@@ -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
+}

+ 4
- 0
backend/lib/services/user.js Просмотреть файл

@@ -223,4 +223,8 @@ module.exports = class UserService extends Schmervice.Service {
223 223
 
224 224
         return passwordRow ? passwordRow.token : null
225 225
     }
226
+
227
+    async getStatus(id){
228
+        // not sure how to write this part
229
+    }
226 230
 }

Загрузка…
Отмена
Сохранить