@gls_spain/gps-common 34.9.1 → 34.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -1
- package/.eslintrc.json +11 -11
- package/.idea/codeStyles/Project.xml +36 -36
- package/.idea/codeStyles/codeStyleConfig.xml +4 -4
- package/.idea/gps-common.iml +11 -11
- package/.idea/inspectionProfiles/Project_Default.xml +6 -6
- package/.idea/jsLibraryMappings.xml +5 -5
- package/.idea/misc.xml +5 -5
- package/.idea/modules.xml +7 -7
- package/.idea/prettier.xml +6 -6
- package/.idea/scopes/Source_files.xml +2 -2
- package/.idea/vcs.xml +5 -5
- package/.prettierignore +4 -4
- package/.prettierrc.json +13 -13
- package/.releaserc +17 -17
- package/CHANGELOG.md +1264 -1250
- package/README.md +103 -103
- package/errors/CountersDoNotExistError.js +11 -11
- package/errors/DatabaseNotEmptyError.js +11 -11
- package/errors/DefaultsDoNotExistError.js +11 -11
- package/errors/ExpeditionAlreadyExistsError.js +11 -11
- package/errors/ExpeditionCannotBeDeletedError.js +11 -11
- package/errors/ExpeditionCannotBeUpdatedError.js +11 -11
- package/errors/ExpeditionDoesNotExistError.js +11 -11
- package/errors/GLSRecordingError.js +11 -11
- package/errors/GLSSpainError.js +11 -11
- package/errors/InconsistentSalesSettingsError.js +11 -11
- package/errors/InvalidSaleDestinationError.js +11 -11
- package/errors/LabelDoesNotExistError.js +11 -11
- package/errors/NetworkAlreadyExistsError.js +11 -11
- package/errors/NetworkCannotBeDeletedError.js +11 -11
- package/errors/NetworkCannotBeUpdatedError.js +11 -11
- package/errors/NetworkDoesNotExistError.js +11 -11
- package/errors/RepresentativeAlreadyExistsError.js +11 -11
- package/errors/RepresentativeCannotBeDeletedError.js +11 -11
- package/errors/RepresentativeDoesNotExistError.js +11 -11
- package/errors/SaleAlreadyExistsError.js +11 -11
- package/errors/SaleDoesNotExistError.js +11 -11
- package/errors/ShopAlreadyExistsError.js +11 -11
- package/errors/ShopCannotBeDeletedError.js +11 -11
- package/errors/ShopCannotBeUpdatedError.js +11 -11
- package/errors/ShopCannotSellError.js +11 -11
- package/errors/ShopDoesNotExistError.js +11 -11
- package/errors/ShopNotEnabledError.js +11 -11
- package/errors/UserAlreadyExistsError.js +11 -11
- package/errors/UserCannotBeDeletedError.js +11 -11
- package/errors/UserCannotBeUpdatedError.js +11 -11
- package/errors/UserDoesNotExistError.js +11 -11
- package/errors/WrongNetworkError.js +11 -11
- package/errors/WrongPasswordError.js +11 -11
- package/errors/WrongShopError.js +11 -11
- package/errors/ZoneAlreadyExistsError.js +11 -11
- package/errors/ZoneCannotBeDeletedError.js +11 -11
- package/errors/ZoneDoesNotExistError.js +11 -11
- package/errors/index.js +118 -118
- package/index.js +9 -9
- package/index.test.js +36 -36
- package/jest.config.js +5 -5
- package/open-api-spec/index.js +3715 -3715
- package/package.json +65 -69
- package/schemas/definitions/become.js +5 -5
- package/schemas/definitions/common.js +462 -440
- package/schemas/definitions/counters.js +43 -43
- package/schemas/definitions/defaults.js +140 -140
- package/schemas/definitions/expeditions.js +867 -867
- package/schemas/definitions/gls-spain-integration-events.js +139 -139
- package/schemas/definitions/historic-records.js +90 -90
- package/schemas/definitions/integrations.js +38 -38
- package/schemas/definitions/login.js +38 -38
- package/schemas/definitions/logout.js +8 -8
- package/schemas/definitions/networks.js +123 -123
- package/schemas/definitions/pods.js +26 -26
- package/schemas/definitions/representatives.js +194 -194
- package/schemas/definitions/sales.js +253 -249
- package/schemas/definitions/shops.js +404 -404
- package/schemas/definitions/users.js +337 -337
- package/schemas/definitions/zones.js +92 -92
- package/schemas/index.js +400 -400
- package/scripts/build-documentation.js +40 -40
- package/scripts/build-json-schemas.js +35 -35
- package/.idea/workspace.xml +0 -696
|
@@ -1,337 +1,337 @@
|
|
|
1
|
-
const {
|
|
2
|
-
datetime,
|
|
3
|
-
email,
|
|
4
|
-
phone,
|
|
5
|
-
password,
|
|
6
|
-
uuid,
|
|
7
|
-
createRequest,
|
|
8
|
-
createResponse,
|
|
9
|
-
findRequest,
|
|
10
|
-
findResponse,
|
|
11
|
-
updateRequest,
|
|
12
|
-
updateSelfRequest,
|
|
13
|
-
updateResponse,
|
|
14
|
-
deleteRequest,
|
|
15
|
-
deleteResponse,
|
|
16
|
-
mergeSchemas,
|
|
17
|
-
pickProperties,
|
|
18
|
-
} = require('@gls_spain/common-json-schemas');
|
|
19
|
-
const { address, findAll, findById, findByName } = require('./common');
|
|
20
|
-
const { network, objectWithNetworkId } = require('./networks');
|
|
21
|
-
const { shop, objectWithShopId } = require('./shops');
|
|
22
|
-
|
|
23
|
-
const baseUser = () => ({
|
|
24
|
-
type: 'object',
|
|
25
|
-
properties: {
|
|
26
|
-
_id: uuid(),
|
|
27
|
-
createdAt: datetime(),
|
|
28
|
-
updatedAt: datetime(),
|
|
29
|
-
deletable: { type: 'boolean' },
|
|
30
|
-
username: {
|
|
31
|
-
type: 'string',
|
|
32
|
-
pattern: '^[a-zA-Z0-9]+$',
|
|
33
|
-
minLength: 3,
|
|
34
|
-
description: 'a unique username that cannot be changed later',
|
|
35
|
-
},
|
|
36
|
-
loginEnabled: { type: 'boolean' },
|
|
37
|
-
permissions: { type: 'array', items: { type: 'string', enum: ['canReceiveAllFromDriver'] }, uniqueItems: true },
|
|
38
|
-
role: { type: 'string' },
|
|
39
|
-
name: { type: 'string', trim: true },
|
|
40
|
-
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
41
|
-
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
42
|
-
nif: { type: 'string', trim: true },
|
|
43
|
-
address: address(),
|
|
44
|
-
},
|
|
45
|
-
required: ['_id', 'createdAt', 'updatedAt', 'username', 'deletable', 'loginEnabled', 'permissions', 'role', 'name', 'emails', 'phones'],
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const superAdmin = () => mergeSchemas(baseUser(), { title: 'superAdmin', properties: { role: { enum: ['superAdmin'] } } });
|
|
50
|
-
|
|
51
|
-
const networkAdmin = () =>
|
|
52
|
-
mergeSchemas(baseUser(), {
|
|
53
|
-
title: 'networkAdmin',
|
|
54
|
-
properties: {
|
|
55
|
-
role: { enum: ['networkAdmin'] },
|
|
56
|
-
network: {
|
|
57
|
-
type: 'object',
|
|
58
|
-
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
59
|
-
required: ['_id', 'name'],
|
|
60
|
-
additionalProperties: false,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
required: ['network'],
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const shopUser = () =>
|
|
67
|
-
mergeSchemas(baseUser(), {
|
|
68
|
-
title: 'shopUser',
|
|
69
|
-
properties: {
|
|
70
|
-
role: { enum: ['shopUser'] },
|
|
71
|
-
network: {
|
|
72
|
-
type: 'object',
|
|
73
|
-
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
74
|
-
required: ['_id', 'name'],
|
|
75
|
-
additionalProperties: false,
|
|
76
|
-
},
|
|
77
|
-
shop: {
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
80
|
-
required: ['_id', 'name'],
|
|
81
|
-
additionalProperties: false,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
required: ['network', 'shop'],
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const createSuperAdminRequest = () =>
|
|
88
|
-
createRequest({
|
|
89
|
-
type: 'object',
|
|
90
|
-
properties: {
|
|
91
|
-
...pickProperties(superAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
92
|
-
password: password(),
|
|
93
|
-
},
|
|
94
|
-
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
95
|
-
additionalProperties: false,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const createSuperAdminResponse = () => createResponse(superAdmin());
|
|
99
|
-
|
|
100
|
-
const findSuperAdminsRequest = () => findRequest({ oneOf: [findAll(), findById(), findByName()] });
|
|
101
|
-
|
|
102
|
-
const findSuperAdminsResponse = () => findResponse(superAdmin());
|
|
103
|
-
|
|
104
|
-
const updateSuperAdminRequest = () =>
|
|
105
|
-
updateRequest(
|
|
106
|
-
findById(),
|
|
107
|
-
{
|
|
108
|
-
type: 'object',
|
|
109
|
-
properties: {
|
|
110
|
-
...pickProperties(superAdmin(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
111
|
-
password: password(),
|
|
112
|
-
},
|
|
113
|
-
minProperties: 1,
|
|
114
|
-
additionalProperties: false,
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
type: 'object',
|
|
118
|
-
properties: { ...pickProperties(superAdmin(), ['emails', 'phones']) },
|
|
119
|
-
minProperties: 1,
|
|
120
|
-
additionalProperties: false,
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const updateSuperAdminResponse = () => updateResponse(superAdmin());
|
|
125
|
-
|
|
126
|
-
const deleteSuperAdminRequest = () => deleteRequest(findById());
|
|
127
|
-
|
|
128
|
-
const deleteSuperAdminResponse = () => deleteResponse(superAdmin());
|
|
129
|
-
|
|
130
|
-
const createNetworkAdminRequest = () =>
|
|
131
|
-
createRequest(
|
|
132
|
-
mergeSchemas(
|
|
133
|
-
{
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: {
|
|
136
|
-
...pickProperties(networkAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
137
|
-
password: password(),
|
|
138
|
-
},
|
|
139
|
-
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
140
|
-
additionalProperties: false,
|
|
141
|
-
},
|
|
142
|
-
objectWithNetworkId(),
|
|
143
|
-
),
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const createNetworkAdminResponse = () => createResponse(networkAdmin());
|
|
147
|
-
|
|
148
|
-
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
149
|
-
|
|
150
|
-
const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
|
|
151
|
-
|
|
152
|
-
const findNetworkAdminsRequest = () =>
|
|
153
|
-
findRequest({
|
|
154
|
-
oneOf: [findAll(), findById(), findByName(), findByNetwork(), findByNetworkAndName()],
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const findNetworkAdminsResponse = () => findResponse(networkAdmin());
|
|
158
|
-
|
|
159
|
-
const updateNetworkAdminRequest = () =>
|
|
160
|
-
updateRequest(
|
|
161
|
-
findById(),
|
|
162
|
-
{
|
|
163
|
-
type: 'object',
|
|
164
|
-
properties: {
|
|
165
|
-
...pickProperties(networkAdmin(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
166
|
-
password: password(),
|
|
167
|
-
},
|
|
168
|
-
minProperties: 1,
|
|
169
|
-
additionalProperties: false,
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
type: 'object',
|
|
173
|
-
properties: { ...pickProperties(networkAdmin(), ['emails', 'phones']) },
|
|
174
|
-
minProperties: 1,
|
|
175
|
-
additionalProperties: false,
|
|
176
|
-
},
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const updateSelfNetworkAdminRequest = () =>
|
|
180
|
-
updateSelfRequest(
|
|
181
|
-
{
|
|
182
|
-
type: 'object',
|
|
183
|
-
properties: {
|
|
184
|
-
...pickProperties(networkAdmin(), ['name', 'emails', 'phones'], ['nif', 'address']),
|
|
185
|
-
password: {
|
|
186
|
-
type: 'object',
|
|
187
|
-
properties: { old: password(), new: password() },
|
|
188
|
-
required: ['old', 'new'],
|
|
189
|
-
additionalProperties: false,
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
minProperties: 1,
|
|
193
|
-
additionalProperties: false,
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
type: 'object',
|
|
197
|
-
properties: { ...pickProperties(networkAdmin(), ['emails', 'phones']) },
|
|
198
|
-
minProperties: 1,
|
|
199
|
-
additionalProperties: false,
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
const updateNetworkAdminResponse = () => updateResponse(networkAdmin());
|
|
204
|
-
|
|
205
|
-
const deleteNetworkAdminRequest = () => deleteRequest(findById());
|
|
206
|
-
|
|
207
|
-
const deleteNetworkAdminResponse = () => deleteResponse(networkAdmin());
|
|
208
|
-
|
|
209
|
-
const createShopUserRequest = () =>
|
|
210
|
-
createRequest(
|
|
211
|
-
mergeSchemas(
|
|
212
|
-
{
|
|
213
|
-
type: 'object',
|
|
214
|
-
properties: {
|
|
215
|
-
...pickProperties(shopUser(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
216
|
-
password: password(),
|
|
217
|
-
},
|
|
218
|
-
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
219
|
-
additionalProperties: false,
|
|
220
|
-
},
|
|
221
|
-
objectWithNetworkId(),
|
|
222
|
-
objectWithShopId(),
|
|
223
|
-
),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const createShopUserResponse = () => createResponse(shopUser());
|
|
227
|
-
|
|
228
|
-
const findByNetworkAndShop = () => mergeSchemas(objectWithNetworkId(), objectWithShopId(), { title: 'find by network and shop' });
|
|
229
|
-
|
|
230
|
-
const findByNetworkAndShopAndName = () =>
|
|
231
|
-
mergeSchemas(findByNetworkAndShop(), findByName(), { title: 'find by network and shop and name' });
|
|
232
|
-
|
|
233
|
-
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
234
|
-
|
|
235
|
-
const findByShopAndName = () => mergeSchemas(findByShop(), findByName(), { title: 'find by shop and name' });
|
|
236
|
-
|
|
237
|
-
const findShopUsersSuperAdminRequest = () =>
|
|
238
|
-
findRequest({
|
|
239
|
-
oneOf: [
|
|
240
|
-
findAll(),
|
|
241
|
-
findById(),
|
|
242
|
-
findByName(),
|
|
243
|
-
findByNetwork(),
|
|
244
|
-
findByNetworkAndName(),
|
|
245
|
-
findByNetworkAndShop(),
|
|
246
|
-
findByNetworkAndShopAndName(),
|
|
247
|
-
],
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const findShopUsersNetworkAdminRequest = () =>
|
|
251
|
-
findRequest({ oneOf: [findAll(), findById(), findByName(), findByShop(), findByShopAndName()] });
|
|
252
|
-
|
|
253
|
-
const findShopUsersResponse = () => findResponse(shopUser());
|
|
254
|
-
|
|
255
|
-
const updateShopUserRequest = () =>
|
|
256
|
-
updateRequest(
|
|
257
|
-
findById(),
|
|
258
|
-
{
|
|
259
|
-
type: 'object',
|
|
260
|
-
properties: {
|
|
261
|
-
...pickProperties(shopUser(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
262
|
-
password: password(),
|
|
263
|
-
},
|
|
264
|
-
minProperties: 1,
|
|
265
|
-
additionalProperties: false,
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
type: 'object',
|
|
269
|
-
properties: { ...pickProperties(shopUser(), ['emails', 'phones']) },
|
|
270
|
-
minProperties: 1,
|
|
271
|
-
additionalProperties: false,
|
|
272
|
-
},
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const updateSelfShopUserRequest = () =>
|
|
276
|
-
updateSelfRequest(
|
|
277
|
-
{
|
|
278
|
-
type: 'object',
|
|
279
|
-
properties: {
|
|
280
|
-
...pickProperties(shopUser(), ['name', 'emails', 'phones'], ['nif', 'address']),
|
|
281
|
-
password: {
|
|
282
|
-
type: 'object',
|
|
283
|
-
properties: { old: password(), new: password() },
|
|
284
|
-
required: ['old', 'new'],
|
|
285
|
-
additionalProperties: false,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
minProperties: 1,
|
|
289
|
-
additionalProperties: false,
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
type: 'object',
|
|
293
|
-
properties: { ...pickProperties(shopUser(), ['emails', 'phones']) },
|
|
294
|
-
minProperties: 1,
|
|
295
|
-
additionalProperties: false,
|
|
296
|
-
},
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
const updateShopUserResponse = () => updateResponse(shopUser());
|
|
300
|
-
|
|
301
|
-
const deleteShopUserRequest = () => deleteRequest(findById());
|
|
302
|
-
|
|
303
|
-
const deleteShopUserResponse = () => deleteResponse(shopUser());
|
|
304
|
-
|
|
305
|
-
module.exports = {
|
|
306
|
-
baseUser,
|
|
307
|
-
superAdmin,
|
|
308
|
-
createSuperAdminRequest,
|
|
309
|
-
createSuperAdminResponse,
|
|
310
|
-
findSuperAdminsRequest,
|
|
311
|
-
findSuperAdminsResponse,
|
|
312
|
-
updateSuperAdminRequest,
|
|
313
|
-
updateSuperAdminResponse,
|
|
314
|
-
deleteSuperAdminRequest,
|
|
315
|
-
deleteSuperAdminResponse,
|
|
316
|
-
networkAdmin,
|
|
317
|
-
createNetworkAdminRequest,
|
|
318
|
-
createNetworkAdminResponse,
|
|
319
|
-
findNetworkAdminsRequest,
|
|
320
|
-
findNetworkAdminsResponse,
|
|
321
|
-
updateNetworkAdminRequest,
|
|
322
|
-
updateSelfNetworkAdminRequest,
|
|
323
|
-
updateNetworkAdminResponse,
|
|
324
|
-
deleteNetworkAdminRequest,
|
|
325
|
-
deleteNetworkAdminResponse,
|
|
326
|
-
shopUser,
|
|
327
|
-
createShopUserRequest,
|
|
328
|
-
createShopUserResponse,
|
|
329
|
-
findShopUsersSuperAdminRequest,
|
|
330
|
-
findShopUsersNetworkAdminRequest,
|
|
331
|
-
findShopUsersResponse,
|
|
332
|
-
updateShopUserRequest,
|
|
333
|
-
updateSelfShopUserRequest,
|
|
334
|
-
updateShopUserResponse,
|
|
335
|
-
deleteShopUserRequest,
|
|
336
|
-
deleteShopUserResponse,
|
|
337
|
-
};
|
|
1
|
+
const {
|
|
2
|
+
datetime,
|
|
3
|
+
email,
|
|
4
|
+
phone,
|
|
5
|
+
password,
|
|
6
|
+
uuid,
|
|
7
|
+
createRequest,
|
|
8
|
+
createResponse,
|
|
9
|
+
findRequest,
|
|
10
|
+
findResponse,
|
|
11
|
+
updateRequest,
|
|
12
|
+
updateSelfRequest,
|
|
13
|
+
updateResponse,
|
|
14
|
+
deleteRequest,
|
|
15
|
+
deleteResponse,
|
|
16
|
+
mergeSchemas,
|
|
17
|
+
pickProperties,
|
|
18
|
+
} = require('@gls_spain/common-json-schemas');
|
|
19
|
+
const { address, findAll, findById, findByName } = require('./common');
|
|
20
|
+
const { network, objectWithNetworkId } = require('./networks');
|
|
21
|
+
const { shop, objectWithShopId } = require('./shops');
|
|
22
|
+
|
|
23
|
+
const baseUser = () => ({
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
_id: uuid(),
|
|
27
|
+
createdAt: datetime(),
|
|
28
|
+
updatedAt: datetime(),
|
|
29
|
+
deletable: { type: 'boolean' },
|
|
30
|
+
username: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
pattern: '^[a-zA-Z0-9]+$',
|
|
33
|
+
minLength: 3,
|
|
34
|
+
description: 'a unique username that cannot be changed later',
|
|
35
|
+
},
|
|
36
|
+
loginEnabled: { type: 'boolean' },
|
|
37
|
+
permissions: { type: 'array', items: { type: 'string', enum: ['canReceiveAllFromDriver'] }, uniqueItems: true },
|
|
38
|
+
role: { type: 'string' },
|
|
39
|
+
name: { type: 'string', trim: true },
|
|
40
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
41
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
42
|
+
nif: { type: 'string', trim: true },
|
|
43
|
+
address: address(),
|
|
44
|
+
},
|
|
45
|
+
required: ['_id', 'createdAt', 'updatedAt', 'username', 'deletable', 'loginEnabled', 'permissions', 'role', 'name', 'emails', 'phones'],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const superAdmin = () => mergeSchemas(baseUser(), { title: 'superAdmin', properties: { role: { enum: ['superAdmin'] } } });
|
|
50
|
+
|
|
51
|
+
const networkAdmin = () =>
|
|
52
|
+
mergeSchemas(baseUser(), {
|
|
53
|
+
title: 'networkAdmin',
|
|
54
|
+
properties: {
|
|
55
|
+
role: { enum: ['networkAdmin'] },
|
|
56
|
+
network: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
59
|
+
required: ['_id', 'name'],
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
required: ['network'],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const shopUser = () =>
|
|
67
|
+
mergeSchemas(baseUser(), {
|
|
68
|
+
title: 'shopUser',
|
|
69
|
+
properties: {
|
|
70
|
+
role: { enum: ['shopUser'] },
|
|
71
|
+
network: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
74
|
+
required: ['_id', 'name'],
|
|
75
|
+
additionalProperties: false,
|
|
76
|
+
},
|
|
77
|
+
shop: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
80
|
+
required: ['_id', 'name'],
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ['network', 'shop'],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const createSuperAdminRequest = () =>
|
|
88
|
+
createRequest({
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
...pickProperties(superAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
92
|
+
password: password(),
|
|
93
|
+
},
|
|
94
|
+
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const createSuperAdminResponse = () => createResponse(superAdmin());
|
|
99
|
+
|
|
100
|
+
const findSuperAdminsRequest = () => findRequest({ oneOf: [findAll(), findById(), findByName()] });
|
|
101
|
+
|
|
102
|
+
const findSuperAdminsResponse = () => findResponse(superAdmin());
|
|
103
|
+
|
|
104
|
+
const updateSuperAdminRequest = () =>
|
|
105
|
+
updateRequest(
|
|
106
|
+
findById(),
|
|
107
|
+
{
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
...pickProperties(superAdmin(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
111
|
+
password: password(),
|
|
112
|
+
},
|
|
113
|
+
minProperties: 1,
|
|
114
|
+
additionalProperties: false,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: { ...pickProperties(superAdmin(), ['emails', 'phones']) },
|
|
119
|
+
minProperties: 1,
|
|
120
|
+
additionalProperties: false,
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const updateSuperAdminResponse = () => updateResponse(superAdmin());
|
|
125
|
+
|
|
126
|
+
const deleteSuperAdminRequest = () => deleteRequest(findById());
|
|
127
|
+
|
|
128
|
+
const deleteSuperAdminResponse = () => deleteResponse(superAdmin());
|
|
129
|
+
|
|
130
|
+
const createNetworkAdminRequest = () =>
|
|
131
|
+
createRequest(
|
|
132
|
+
mergeSchemas(
|
|
133
|
+
{
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
...pickProperties(networkAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
137
|
+
password: password(),
|
|
138
|
+
},
|
|
139
|
+
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
},
|
|
142
|
+
objectWithNetworkId(),
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const createNetworkAdminResponse = () => createResponse(networkAdmin());
|
|
147
|
+
|
|
148
|
+
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
149
|
+
|
|
150
|
+
const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
|
|
151
|
+
|
|
152
|
+
const findNetworkAdminsRequest = () =>
|
|
153
|
+
findRequest({
|
|
154
|
+
oneOf: [findAll(), findById(), findByName(), findByNetwork(), findByNetworkAndName()],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const findNetworkAdminsResponse = () => findResponse(networkAdmin());
|
|
158
|
+
|
|
159
|
+
const updateNetworkAdminRequest = () =>
|
|
160
|
+
updateRequest(
|
|
161
|
+
findById(),
|
|
162
|
+
{
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
...pickProperties(networkAdmin(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
166
|
+
password: password(),
|
|
167
|
+
},
|
|
168
|
+
minProperties: 1,
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'object',
|
|
173
|
+
properties: { ...pickProperties(networkAdmin(), ['emails', 'phones']) },
|
|
174
|
+
minProperties: 1,
|
|
175
|
+
additionalProperties: false,
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const updateSelfNetworkAdminRequest = () =>
|
|
180
|
+
updateSelfRequest(
|
|
181
|
+
{
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: {
|
|
184
|
+
...pickProperties(networkAdmin(), ['name', 'emails', 'phones'], ['nif', 'address']),
|
|
185
|
+
password: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: { old: password(), new: password() },
|
|
188
|
+
required: ['old', 'new'],
|
|
189
|
+
additionalProperties: false,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
minProperties: 1,
|
|
193
|
+
additionalProperties: false,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: 'object',
|
|
197
|
+
properties: { ...pickProperties(networkAdmin(), ['emails', 'phones']) },
|
|
198
|
+
minProperties: 1,
|
|
199
|
+
additionalProperties: false,
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const updateNetworkAdminResponse = () => updateResponse(networkAdmin());
|
|
204
|
+
|
|
205
|
+
const deleteNetworkAdminRequest = () => deleteRequest(findById());
|
|
206
|
+
|
|
207
|
+
const deleteNetworkAdminResponse = () => deleteResponse(networkAdmin());
|
|
208
|
+
|
|
209
|
+
const createShopUserRequest = () =>
|
|
210
|
+
createRequest(
|
|
211
|
+
mergeSchemas(
|
|
212
|
+
{
|
|
213
|
+
type: 'object',
|
|
214
|
+
properties: {
|
|
215
|
+
...pickProperties(shopUser(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
|
|
216
|
+
password: password(),
|
|
217
|
+
},
|
|
218
|
+
required: ['username', 'loginEnabled', 'name', 'password'],
|
|
219
|
+
additionalProperties: false,
|
|
220
|
+
},
|
|
221
|
+
objectWithNetworkId(),
|
|
222
|
+
objectWithShopId(),
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const createShopUserResponse = () => createResponse(shopUser());
|
|
227
|
+
|
|
228
|
+
const findByNetworkAndShop = () => mergeSchemas(objectWithNetworkId(), objectWithShopId(), { title: 'find by network and shop' });
|
|
229
|
+
|
|
230
|
+
const findByNetworkAndShopAndName = () =>
|
|
231
|
+
mergeSchemas(findByNetworkAndShop(), findByName(), { title: 'find by network and shop and name' });
|
|
232
|
+
|
|
233
|
+
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
234
|
+
|
|
235
|
+
const findByShopAndName = () => mergeSchemas(findByShop(), findByName(), { title: 'find by shop and name' });
|
|
236
|
+
|
|
237
|
+
const findShopUsersSuperAdminRequest = () =>
|
|
238
|
+
findRequest({
|
|
239
|
+
oneOf: [
|
|
240
|
+
findAll(),
|
|
241
|
+
findById(),
|
|
242
|
+
findByName(),
|
|
243
|
+
findByNetwork(),
|
|
244
|
+
findByNetworkAndName(),
|
|
245
|
+
findByNetworkAndShop(),
|
|
246
|
+
findByNetworkAndShopAndName(),
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const findShopUsersNetworkAdminRequest = () =>
|
|
251
|
+
findRequest({ oneOf: [findAll(), findById(), findByName(), findByShop(), findByShopAndName()] });
|
|
252
|
+
|
|
253
|
+
const findShopUsersResponse = () => findResponse(shopUser());
|
|
254
|
+
|
|
255
|
+
const updateShopUserRequest = () =>
|
|
256
|
+
updateRequest(
|
|
257
|
+
findById(),
|
|
258
|
+
{
|
|
259
|
+
type: 'object',
|
|
260
|
+
properties: {
|
|
261
|
+
...pickProperties(shopUser(), ['loginEnabled', 'name', 'emails', 'phones'], ['nif', 'address']),
|
|
262
|
+
password: password(),
|
|
263
|
+
},
|
|
264
|
+
minProperties: 1,
|
|
265
|
+
additionalProperties: false,
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
type: 'object',
|
|
269
|
+
properties: { ...pickProperties(shopUser(), ['emails', 'phones']) },
|
|
270
|
+
minProperties: 1,
|
|
271
|
+
additionalProperties: false,
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const updateSelfShopUserRequest = () =>
|
|
276
|
+
updateSelfRequest(
|
|
277
|
+
{
|
|
278
|
+
type: 'object',
|
|
279
|
+
properties: {
|
|
280
|
+
...pickProperties(shopUser(), ['name', 'emails', 'phones'], ['nif', 'address']),
|
|
281
|
+
password: {
|
|
282
|
+
type: 'object',
|
|
283
|
+
properties: { old: password(), new: password() },
|
|
284
|
+
required: ['old', 'new'],
|
|
285
|
+
additionalProperties: false,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
minProperties: 1,
|
|
289
|
+
additionalProperties: false,
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
type: 'object',
|
|
293
|
+
properties: { ...pickProperties(shopUser(), ['emails', 'phones']) },
|
|
294
|
+
minProperties: 1,
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
const updateShopUserResponse = () => updateResponse(shopUser());
|
|
300
|
+
|
|
301
|
+
const deleteShopUserRequest = () => deleteRequest(findById());
|
|
302
|
+
|
|
303
|
+
const deleteShopUserResponse = () => deleteResponse(shopUser());
|
|
304
|
+
|
|
305
|
+
module.exports = {
|
|
306
|
+
baseUser,
|
|
307
|
+
superAdmin,
|
|
308
|
+
createSuperAdminRequest,
|
|
309
|
+
createSuperAdminResponse,
|
|
310
|
+
findSuperAdminsRequest,
|
|
311
|
+
findSuperAdminsResponse,
|
|
312
|
+
updateSuperAdminRequest,
|
|
313
|
+
updateSuperAdminResponse,
|
|
314
|
+
deleteSuperAdminRequest,
|
|
315
|
+
deleteSuperAdminResponse,
|
|
316
|
+
networkAdmin,
|
|
317
|
+
createNetworkAdminRequest,
|
|
318
|
+
createNetworkAdminResponse,
|
|
319
|
+
findNetworkAdminsRequest,
|
|
320
|
+
findNetworkAdminsResponse,
|
|
321
|
+
updateNetworkAdminRequest,
|
|
322
|
+
updateSelfNetworkAdminRequest,
|
|
323
|
+
updateNetworkAdminResponse,
|
|
324
|
+
deleteNetworkAdminRequest,
|
|
325
|
+
deleteNetworkAdminResponse,
|
|
326
|
+
shopUser,
|
|
327
|
+
createShopUserRequest,
|
|
328
|
+
createShopUserResponse,
|
|
329
|
+
findShopUsersSuperAdminRequest,
|
|
330
|
+
findShopUsersNetworkAdminRequest,
|
|
331
|
+
findShopUsersResponse,
|
|
332
|
+
updateShopUserRequest,
|
|
333
|
+
updateSelfShopUserRequest,
|
|
334
|
+
updateShopUserResponse,
|
|
335
|
+
deleteShopUserRequest,
|
|
336
|
+
deleteShopUserResponse,
|
|
337
|
+
};
|