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

:boom: Removed unnecessary user routes

juan-filtering-match-pool
tomit4 2 лет назад
Родитель
Сommit
927846588b
2 измененных файлов: 0 добавлений и 155 удалений
  1. 0
    67
      backend/lib/routes/user/current.js
  2. 0
    88
      backend/lib/routes/user/list-profiles.js

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

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',
11
-            notes: 'Returns a user item by the id passed in the path',
12
-        },
13
-    },
14
-}
15
-
16
-/** Validator functions by request method */
17
-const validators = {
18
-    get: {
19
-        params: params.userName,
20
-    },
21
-}
22
-
23
-module.exports = {
24
-    method: 'get',
25
-    path: '/{name}',
26
-    options: {
27
-        ...pluginConfig.docs.get,
28
-        tags: ['api'],
29
-        auth: 'default_jwt',
30
-        handler: async function (request, h) {
31
-            try {
32
-                const auth = {
33
-                    credentials: request.auth.credentials,
34
-                    token: request.auth.artifacts.token,
35
-                }
36
-
37
-                // /** Get the data for your endpoint */
38
-                // const { User } = request.models()
39
-                // const all = await User.query()
40
-
41
-                const { displayService } = request.services()
42
-                const user = displayService.user(auth.credentials, auth.token)
43
-
44
-                return {
45
-                    ok: true,
46
-                    handler: pluginConfig.handlerType,
47
-                    data: { name: request.params.name },
48
-                }
49
-            } catch (err) {
50
-                return {
51
-                    ok: false,
52
-                    handler: pluginConfig.handlerType,
53
-                    data: { error: err },
54
-                }
55
-            }
56
-        },
57
-        validate: validators.get,
58
-        response: {
59
-            schema: Joi.object({
60
-                ok: Joi.bool(),
61
-                handler: Joi.string(),
62
-                data: validators.get.params,
63
-            }).label('user_name_res'),
64
-            failAction: 'log',
65
-        },
66
-    },
67
-}

+ 0
- 88
backend/lib/routes/user/list-profiles.js Просмотреть файл

1
-'use strict'
2
-
3
-const Joi = require('joi')
4
-const errorSchema = require('../../schemas/errors')
5
-const profileSchema = require('../../schemas/profiles')
6
-const params = require('../../schemas/params')
7
-
8
-const pluginConfig = {
9
-    handlerType: 'user',
10
-    docs: {
11
-        description: 'profiles',
12
-        notes: 'A list of profiles associated with this user',
13
-    },
14
-}
15
-
16
-const validators = {
17
-    /** Validate the header (cookie check) */
18
-    // headers: true,
19
-
20
-    /** Validate the route params (/active/{thing}) */
21
-    params: params.userId,
22
-
23
-    /** Validate the route query (/active/{thing}?limit=10&offset=10) */
24
-    // query: true,
25
-    /** Validate the incoming payload (POST method) */
26
-    // payload: true,
27
-}
28
-
29
-const responseSchemas = {
30
-    profilesList: profileSchema.list,
31
-    error: errorSchema.single,
32
-}
33
-
34
-module.exports = {
35
-    method: 'GET',
36
-    path: '/{user_id}/profiles',
37
-    options: {
38
-        ...pluginConfig.docs,
39
-        tags: ['api'],
40
-        auth: 'default_jwt',
41
-        cors: true,
42
-        handler: async function (request, h) {
43
-            const { userService, profileService } = request.server.services()
44
-            const userId = request.params.user_id
45
-            const user = await userService.findById(userId)
46
-            const type = user.is_poster == 1 ? 'poster' : 'seeker'
47
-            const profiles = await profileService.getCompleteProfilesFor(
48
-                userId,
49
-                type,
50
-            )
51
-            try {
52
-                return {
53
-                    ok: true,
54
-                    handler: pluginConfig.handlerType,
55
-                    data: profiles,
56
-                }
57
-            } catch (err) {
58
-                return {
59
-                    ok: false,
60
-                    handler: pluginConfig.handlerType,
61
-                    data: { error: `${err}` },
62
-                }
63
-            }
64
-        },
65
-
66
-        /** Validate based on validators object */
67
-        validate: {
68
-            ...validators,
69
-            failAction: 'log',
70
-        },
71
-
72
-        /** Validate the server response */
73
-        response: {
74
-            status: {
75
-                200: Joi.object({
76
-                    ok: Joi.bool(),
77
-                    handler: Joi.string(),
78
-                    data: responseSchemas.profilesList,
79
-                }).label('list_profiles_res'),
80
-                500: Joi.object({
81
-                    ok: Joi.bool(),
82
-                    handler: Joi.string(),
83
-                    data: responseSchemas.error,
84
-                }).label('error_single_res'),
85
-            },
86
-        },
87
-    },
88
-}

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