@gls_spain/gps-common 27.0.0
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/.eslintrc.json +11 -0
- package/.idea/codeStyles/Project.xml +37 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/gps-common.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/watcherTasks.xml +45 -0
- package/.prettierignore +5 -0
- package/.prettierrc.json +13 -0
- package/.releaserc +17 -0
- package/CHANGELOG.md +848 -0
- package/README.md +122 -0
- package/errors/DatabaseNotEmptyError.js +9 -0
- package/errors/DefaultsDoNotExistError.js +9 -0
- package/errors/ExpeditionAlreadyExistsError.js +9 -0
- package/errors/ExpeditionCannotBeDeletedError.js +9 -0
- package/errors/ExpeditionCannotBeUpdatedError.js +9 -0
- package/errors/ExpeditionDoesNotExistError.js +9 -0
- package/errors/JobDoesNotExistError.js +9 -0
- package/errors/NetworkAlreadyExistsError.js +9 -0
- package/errors/NetworkCannotBeDeletedError.js +9 -0
- package/errors/NetworkDoesNotExistError.js +9 -0
- package/errors/RepresentativeAlreadyExistsError.js +9 -0
- package/errors/RepresentativeCannotBeDeletedError.js +9 -0
- package/errors/RepresentativeDoesNotExistError.js +9 -0
- package/errors/ShopAlreadyExistsError.js +9 -0
- package/errors/ShopCannotBeDeletedError.js +9 -0
- package/errors/ShopDoesNotExistError.js +9 -0
- package/errors/ShopNotEnabledError.js +9 -0
- package/errors/UserAlreadyExistsError.js +9 -0
- package/errors/UserCannotBeDeletedError.js +9 -0
- package/errors/UserCannotBeUpdatedError.js +9 -0
- package/errors/UserDoesNotExistError.js +9 -0
- package/errors/WrongNetworkError.js +9 -0
- package/errors/WrongPasswordError.js +9 -0
- package/errors/WrongShopError.js +9 -0
- package/errors/ZoneAlreadyExistsError.js +9 -0
- package/errors/ZoneCannotBeDeletedError.js +9 -0
- package/errors/ZoneDoesNotExistError.js +9 -0
- package/errors/index.js +88 -0
- package/index.js +9 -0
- package/index.test.js +35 -0
- package/jest.config.js +5 -0
- package/open-api-spec/index.js +2920 -0
- package/package.json +68 -0
- package/schemas/definitions/become.js +5 -0
- package/schemas/definitions/common.js +172 -0
- package/schemas/definitions/defaults.js +84 -0
- package/schemas/definitions/expeditions.js +637 -0
- package/schemas/definitions/init.js +37 -0
- package/schemas/definitions/integration-events.js +127 -0
- package/schemas/definitions/jobs.js +124 -0
- package/schemas/definitions/login.js +38 -0
- package/schemas/definitions/logout.js +8 -0
- package/schemas/definitions/networks.js +107 -0
- package/schemas/definitions/pods.js +37 -0
- package/schemas/definitions/representatives.js +178 -0
- package/schemas/definitions/shops.js +352 -0
- package/schemas/definitions/users.js +373 -0
- package/schemas/definitions/zones.js +92 -0
- package/schemas/index.js +335 -0
- package/scripts/build-documentation.js +40 -0
- package/scripts/build-json-schemas.js +35 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
const omit = require('lodash/omit');
|
|
2
|
+
const {
|
|
3
|
+
uuid,
|
|
4
|
+
datetime,
|
|
5
|
+
email,
|
|
6
|
+
phone,
|
|
7
|
+
money,
|
|
8
|
+
objectWithUuid,
|
|
9
|
+
createRequest,
|
|
10
|
+
createResponse,
|
|
11
|
+
findRequest,
|
|
12
|
+
findResponse,
|
|
13
|
+
updateRequest,
|
|
14
|
+
updateResponse,
|
|
15
|
+
deleteRequest,
|
|
16
|
+
deleteResponse,
|
|
17
|
+
mergeSchemas,
|
|
18
|
+
pickProperties,
|
|
19
|
+
} = require('@gls_spain/common-json-schemas');
|
|
20
|
+
const { date, findById, findByIds, tags } = require('./common');
|
|
21
|
+
const { address } = require('./common');
|
|
22
|
+
const { network } = require('./networks');
|
|
23
|
+
const { shop, objectWithShopId } = require('./shops');
|
|
24
|
+
const { derivationSettings } = require('./defaults');
|
|
25
|
+
|
|
26
|
+
const objectWithAgencyCode = () => ({
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: { code: { type: 'integer' } },
|
|
29
|
+
required: ['code'],
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const expeditionAddress = () => ({
|
|
34
|
+
title: 'expedition address',
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
name: { type: 'string' },
|
|
38
|
+
contact: { type: 'string' },
|
|
39
|
+
department: { type: 'string' },
|
|
40
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
41
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
42
|
+
nif: { type: 'string' },
|
|
43
|
+
address: address(),
|
|
44
|
+
agency: objectWithAgencyCode(),
|
|
45
|
+
},
|
|
46
|
+
required: ['name', 'emails', 'phones', 'address', 'agency'],
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const driver = () => ({
|
|
51
|
+
title: 'driver',
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
agency: { type: 'string' },
|
|
55
|
+
code: { type: 'string' },
|
|
56
|
+
device: { type: 'string' },
|
|
57
|
+
},
|
|
58
|
+
required: ['agency', 'code', 'device'],
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const customer = () => ({
|
|
63
|
+
title: 'customer',
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
name: { type: 'string' },
|
|
67
|
+
nif: { type: 'string' },
|
|
68
|
+
pod: objectWithUuid(),
|
|
69
|
+
},
|
|
70
|
+
required: ['name', 'nif', 'pod'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const customerWithPod = () => ({
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
name: { type: 'string' },
|
|
78
|
+
nif: { type: 'string' },
|
|
79
|
+
pod: { type: 'string', contentMediaType: 'image/jpg', contentEncoding: 'base64' },
|
|
80
|
+
},
|
|
81
|
+
required: ['name', 'nif', 'pod'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const processedWithDriver = () => ({
|
|
86
|
+
title: 'processed with driver',
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {
|
|
89
|
+
driver: driver(),
|
|
90
|
+
at: datetime(),
|
|
91
|
+
},
|
|
92
|
+
required: ['at', 'driver'],
|
|
93
|
+
additionalProperties: false,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const processedWithCustomer = () => ({
|
|
97
|
+
title: 'processed with customer',
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
customer: customer(),
|
|
101
|
+
at: datetime(),
|
|
102
|
+
},
|
|
103
|
+
required: ['at', 'customer'],
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const processedWithCustomerWithPod = () => ({
|
|
108
|
+
title: 'processed with customer',
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
customer: customerWithPod(),
|
|
112
|
+
at: datetime(),
|
|
113
|
+
},
|
|
114
|
+
required: ['at', 'customer'],
|
|
115
|
+
additionalProperties: false,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const expedition = () => ({
|
|
119
|
+
title: 'expedition',
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
_id: uuid(),
|
|
123
|
+
createdAt: datetime(),
|
|
124
|
+
updatedAt: datetime(),
|
|
125
|
+
deletable: { type: 'boolean' },
|
|
126
|
+
network: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: { ...pickProperties(network(), ['_id', 'name', 'integrations']) },
|
|
129
|
+
required: ['_id', 'name', 'integrations'],
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
},
|
|
132
|
+
shop: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
135
|
+
required: ['_id', 'name'],
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
},
|
|
138
|
+
type: { type: 'string', enum: ['delivery', 'pickup', 'sale'] },
|
|
139
|
+
status: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
code: { type: 'string', enum: ['incoming', 'inShop', 'inShopExpired', 'delivered'] },
|
|
143
|
+
receivedFrom: {
|
|
144
|
+
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
145
|
+
description: 'how and when did the expedition enter the shop, only available for status inShop or later',
|
|
146
|
+
},
|
|
147
|
+
givenTo: {
|
|
148
|
+
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
149
|
+
description: 'how and when did the expedition leave the shop, only available for status delivered',
|
|
150
|
+
},
|
|
151
|
+
expiration: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
expirationDate: date(),
|
|
155
|
+
expirationAt: datetime(),
|
|
156
|
+
pendingReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
157
|
+
sentReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
158
|
+
},
|
|
159
|
+
required: ['expirationDate', 'expirationAt', 'pendingReminders', 'sentReminders'],
|
|
160
|
+
additionalProperties: false,
|
|
161
|
+
description: 'when will the expedition expire, only available for deliveries and pickups after reception at the shop',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
required: ['code'],
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
},
|
|
167
|
+
code: { type: 'integer', description: 'GLS codexp' },
|
|
168
|
+
serviceCode: { type: 'integer' },
|
|
169
|
+
scheduleCode: { type: 'integer' },
|
|
170
|
+
date: { type: 'string', format: 'date' },
|
|
171
|
+
expectedDeliveryDate: { type: 'string', format: 'date' },
|
|
172
|
+
derivation: {
|
|
173
|
+
type: 'object',
|
|
174
|
+
properties: {
|
|
175
|
+
totalPrice: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
properties: {
|
|
178
|
+
network: { ...money(), description: 'total amount paid to the network, in cents' },
|
|
179
|
+
shop: { ...money(), description: 'total amount paid to the shop, in cents' },
|
|
180
|
+
},
|
|
181
|
+
required: ['network', 'shop'],
|
|
182
|
+
additionalProperties: false,
|
|
183
|
+
},
|
|
184
|
+
settings: derivationSettings(),
|
|
185
|
+
packages: {
|
|
186
|
+
type: 'array',
|
|
187
|
+
items: {
|
|
188
|
+
type: 'object',
|
|
189
|
+
properties: {
|
|
190
|
+
number: { type: 'integer' },
|
|
191
|
+
weight: { type: 'number' },
|
|
192
|
+
},
|
|
193
|
+
required: ['number', 'weight'],
|
|
194
|
+
additionalProperties: false,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
required: ['totalPrice', 'settings', 'packages'],
|
|
199
|
+
additionalProperties: false,
|
|
200
|
+
description: 'only available for deliveries and pickups after reception at the shop',
|
|
201
|
+
},
|
|
202
|
+
barcodes: { type: 'array', items: { type: 'string' } },
|
|
203
|
+
packageCount: { type: 'integer' },
|
|
204
|
+
weight: { type: 'number' },
|
|
205
|
+
volume: { type: 'number' },
|
|
206
|
+
origin: expeditionAddress(),
|
|
207
|
+
destination: expeditionAddress(),
|
|
208
|
+
sender: expeditionAddress(),
|
|
209
|
+
agency: {
|
|
210
|
+
title: 'expedition agency',
|
|
211
|
+
type: 'object',
|
|
212
|
+
properties: {
|
|
213
|
+
code: { type: 'integer' },
|
|
214
|
+
name: { type: 'string' },
|
|
215
|
+
contact: { type: 'string' },
|
|
216
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
217
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
218
|
+
openingSchedule: { type: 'string' },
|
|
219
|
+
},
|
|
220
|
+
required: ['code', 'name', 'emails', 'phones'],
|
|
221
|
+
additionalProperties: false,
|
|
222
|
+
},
|
|
223
|
+
client: {
|
|
224
|
+
title: 'expedition client',
|
|
225
|
+
type: 'object',
|
|
226
|
+
properties: {
|
|
227
|
+
code: { type: 'integer' },
|
|
228
|
+
name: { type: 'string' },
|
|
229
|
+
agency: objectWithAgencyCode(),
|
|
230
|
+
},
|
|
231
|
+
required: ['code', 'name', 'agency'],
|
|
232
|
+
additionalProperties: false,
|
|
233
|
+
},
|
|
234
|
+
references: {
|
|
235
|
+
type: 'array',
|
|
236
|
+
items: {
|
|
237
|
+
title: 'expedition reference',
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
type: { type: 'string' },
|
|
241
|
+
value: { type: 'string' },
|
|
242
|
+
},
|
|
243
|
+
required: ['type', 'value'],
|
|
244
|
+
additionalProperties: false,
|
|
245
|
+
description: 'may have duplicates',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
packages: {
|
|
249
|
+
type: 'array',
|
|
250
|
+
items: {
|
|
251
|
+
title: 'expedition package',
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: {
|
|
254
|
+
number: { type: 'integer', description: 'package number in expedition (1, 2, 3), can be sparse' },
|
|
255
|
+
barcodes: { type: 'array', items: { type: 'string' } },
|
|
256
|
+
weight: { type: 'number' },
|
|
257
|
+
width: { type: 'number' },
|
|
258
|
+
length: { type: 'number' },
|
|
259
|
+
height: { type: 'number' },
|
|
260
|
+
},
|
|
261
|
+
required: ['number', 'barcodes'],
|
|
262
|
+
additionalProperties: false,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
notes: { type: 'string' },
|
|
266
|
+
},
|
|
267
|
+
required: [
|
|
268
|
+
'_id',
|
|
269
|
+
'createdAt',
|
|
270
|
+
'updatedAt',
|
|
271
|
+
'deletable',
|
|
272
|
+
'network',
|
|
273
|
+
'shop',
|
|
274
|
+
'type',
|
|
275
|
+
'status',
|
|
276
|
+
'code',
|
|
277
|
+
'serviceCode',
|
|
278
|
+
'scheduleCode',
|
|
279
|
+
'date',
|
|
280
|
+
'expectedDeliveryDate',
|
|
281
|
+
'barcodes',
|
|
282
|
+
'packageCount',
|
|
283
|
+
'weight',
|
|
284
|
+
'origin',
|
|
285
|
+
'destination',
|
|
286
|
+
'sender',
|
|
287
|
+
'agency',
|
|
288
|
+
'client',
|
|
289
|
+
'references',
|
|
290
|
+
'packages',
|
|
291
|
+
],
|
|
292
|
+
additionalProperties: false,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const objectWithExpeditionId = () => ({
|
|
296
|
+
type: 'object',
|
|
297
|
+
properties: { expedition: objectWithUuid() },
|
|
298
|
+
required: ['expedition'],
|
|
299
|
+
additionalProperties: false,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const createExpeditionRequest = () =>
|
|
303
|
+
createRequest({
|
|
304
|
+
type: 'object',
|
|
305
|
+
properties: {
|
|
306
|
+
...pickProperties(expedition(), ['_id', 'createdAt']),
|
|
307
|
+
shop: objectWithShopId().properties.shop,
|
|
308
|
+
...pickProperties(expedition(), [
|
|
309
|
+
'type',
|
|
310
|
+
'code',
|
|
311
|
+
'serviceCode',
|
|
312
|
+
'scheduleCode',
|
|
313
|
+
'date',
|
|
314
|
+
'expectedDeliveryDate',
|
|
315
|
+
'barcodes',
|
|
316
|
+
'packageCount',
|
|
317
|
+
'weight',
|
|
318
|
+
'volume',
|
|
319
|
+
'origin',
|
|
320
|
+
'destination',
|
|
321
|
+
'sender',
|
|
322
|
+
'agency',
|
|
323
|
+
'client',
|
|
324
|
+
'references',
|
|
325
|
+
'packages',
|
|
326
|
+
'notes',
|
|
327
|
+
]),
|
|
328
|
+
tags: tags(),
|
|
329
|
+
},
|
|
330
|
+
required: [
|
|
331
|
+
'shop',
|
|
332
|
+
'type',
|
|
333
|
+
'code',
|
|
334
|
+
'serviceCode',
|
|
335
|
+
'scheduleCode',
|
|
336
|
+
'date',
|
|
337
|
+
'expectedDeliveryDate',
|
|
338
|
+
'packageCount',
|
|
339
|
+
'weight',
|
|
340
|
+
'origin',
|
|
341
|
+
'destination',
|
|
342
|
+
'sender',
|
|
343
|
+
'agency',
|
|
344
|
+
'client',
|
|
345
|
+
],
|
|
346
|
+
additionalProperties: false,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const createExpeditionResponse = () => createResponse(expedition());
|
|
350
|
+
|
|
351
|
+
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
352
|
+
|
|
353
|
+
const findByStatus = () => ({
|
|
354
|
+
title: 'find by status',
|
|
355
|
+
type: 'object',
|
|
356
|
+
properties: {
|
|
357
|
+
status: {
|
|
358
|
+
type: 'object',
|
|
359
|
+
properties: { code: expedition().properties.status.properties.code },
|
|
360
|
+
required: ['code'],
|
|
361
|
+
additionalProperties: false,
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
required: ['status'],
|
|
365
|
+
additionalProperties: false,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const findByShopAndStatus = () => mergeSchemas(findByShop(), findByStatus(), { title: 'find by shop and status' });
|
|
369
|
+
|
|
370
|
+
const findByCode = () => ({
|
|
371
|
+
title: 'find by code',
|
|
372
|
+
type: 'object',
|
|
373
|
+
properties: {
|
|
374
|
+
code: expedition().properties.code,
|
|
375
|
+
},
|
|
376
|
+
required: ['code'],
|
|
377
|
+
additionalProperties: false,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const findExpeditionsRequest = () => findRequest({ oneOf: [findById(), findByShop(), findByShopAndStatus(), findByCode()] });
|
|
381
|
+
|
|
382
|
+
const findExpeditionsResponse = () => findResponse(expedition());
|
|
383
|
+
|
|
384
|
+
const updateExpeditionRequest = () =>
|
|
385
|
+
updateRequest(
|
|
386
|
+
findById(),
|
|
387
|
+
{
|
|
388
|
+
type: 'object',
|
|
389
|
+
properties: {
|
|
390
|
+
...pickProperties(
|
|
391
|
+
expedition(),
|
|
392
|
+
[
|
|
393
|
+
'code',
|
|
394
|
+
'serviceCode',
|
|
395
|
+
'scheduleCode',
|
|
396
|
+
'date',
|
|
397
|
+
'expectedDeliveryDate',
|
|
398
|
+
'barcodes',
|
|
399
|
+
'packageCount',
|
|
400
|
+
'weight',
|
|
401
|
+
'origin',
|
|
402
|
+
'destination',
|
|
403
|
+
'sender',
|
|
404
|
+
'agency',
|
|
405
|
+
'client',
|
|
406
|
+
'references',
|
|
407
|
+
'packages',
|
|
408
|
+
],
|
|
409
|
+
['volume', 'notes'],
|
|
410
|
+
),
|
|
411
|
+
},
|
|
412
|
+
minProperties: 1,
|
|
413
|
+
additionalProperties: false,
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
type: 'object',
|
|
417
|
+
properties: { ...pickProperties(expedition(), ['barcodes', 'references']) },
|
|
418
|
+
minProperties: 1,
|
|
419
|
+
additionalProperties: false,
|
|
420
|
+
},
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const updateExpeditionResponse = () => updateResponse(expedition());
|
|
424
|
+
|
|
425
|
+
const deleteExpeditionRequest = () => deleteRequest(findById());
|
|
426
|
+
|
|
427
|
+
const deleteExpeditionResponse = () => deleteResponse(expedition());
|
|
428
|
+
|
|
429
|
+
const redirectExpeditionRequest = () => ({
|
|
430
|
+
type: 'object',
|
|
431
|
+
properties: {
|
|
432
|
+
find: findById(),
|
|
433
|
+
redirect: objectWithShopId(),
|
|
434
|
+
},
|
|
435
|
+
required: ['find', 'redirect'],
|
|
436
|
+
additionalProperties: false,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const redirectExpeditionResponse = () => ({
|
|
440
|
+
type: 'object',
|
|
441
|
+
properties: { redirected: expedition() },
|
|
442
|
+
required: ['redirected'],
|
|
443
|
+
additionalProperties: false,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
const objectWithTypeAndStatus = () => ({
|
|
447
|
+
type: 'object',
|
|
448
|
+
properties: {
|
|
449
|
+
type: expedition().properties.type,
|
|
450
|
+
status: {
|
|
451
|
+
type: 'object',
|
|
452
|
+
properties: { code: expedition().properties.status.properties.code },
|
|
453
|
+
required: ['code'],
|
|
454
|
+
additionalProperties: false,
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
required: ['type', 'status'],
|
|
458
|
+
additionalProperties: false,
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const scanExpeditionRequest = () => ({
|
|
462
|
+
type: 'object',
|
|
463
|
+
properties: {
|
|
464
|
+
scan: {
|
|
465
|
+
oneOf: [
|
|
466
|
+
{
|
|
467
|
+
title: 'barcode',
|
|
468
|
+
type: 'object',
|
|
469
|
+
properties: { barcode: { type: 'string' } },
|
|
470
|
+
required: ['barcode'],
|
|
471
|
+
additionalProperties: false,
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
title: 'QR code',
|
|
475
|
+
type: 'object',
|
|
476
|
+
properties: { qrCode: { type: 'string' } },
|
|
477
|
+
required: ['qrCode'],
|
|
478
|
+
additionalProperties: false,
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
required: ['scan'],
|
|
484
|
+
additionalProperties: false,
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
const resultOk = () => ({
|
|
488
|
+
title: 'ok',
|
|
489
|
+
type: 'object',
|
|
490
|
+
properties: { ok: expedition() },
|
|
491
|
+
required: ['ok'],
|
|
492
|
+
additionalProperties: false,
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const resultNotFound = () => ({
|
|
496
|
+
title: 'not found',
|
|
497
|
+
type: 'object',
|
|
498
|
+
properties: { notFound: { type: 'boolean', enum: [true] } },
|
|
499
|
+
required: ['notFound'],
|
|
500
|
+
additionalProperties: false,
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const resultAnotherSituation = () => ({
|
|
504
|
+
title: 'another situation',
|
|
505
|
+
type: 'object',
|
|
506
|
+
properties: { anotherSituation: objectWithTypeAndStatus() },
|
|
507
|
+
required: ['anotherSituation'],
|
|
508
|
+
additionalProperties: false,
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
const resultAnotherShop = () => ({
|
|
512
|
+
title: 'another shop',
|
|
513
|
+
type: 'object',
|
|
514
|
+
properties: {
|
|
515
|
+
anotherShop: {
|
|
516
|
+
type: 'object',
|
|
517
|
+
properties: { ...pickProperties(shop(), ['name']) },
|
|
518
|
+
required: ['name'],
|
|
519
|
+
additionalProperties: false,
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
required: ['anotherShop'],
|
|
523
|
+
additionalProperties: false,
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
const resultMultipleResults = () => ({
|
|
527
|
+
title: 'multiple results',
|
|
528
|
+
type: 'object',
|
|
529
|
+
properties: { multipleResults: { type: 'boolean', enum: [true] } },
|
|
530
|
+
required: ['multipleResults'],
|
|
531
|
+
additionalProperties: false,
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const resultError = () => ({
|
|
535
|
+
title: 'error',
|
|
536
|
+
type: 'object',
|
|
537
|
+
properties: { error: { type: 'string' } },
|
|
538
|
+
required: ['error'],
|
|
539
|
+
additionalProperties: false,
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
const scanExpeditionResponse = () => ({
|
|
543
|
+
oneOf: [resultOk(), resultNotFound(), resultAnotherShop(), resultMultipleResults(), resultError()],
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
const processExpeditionsWithDriverRequest = () => ({
|
|
547
|
+
type: 'object',
|
|
548
|
+
properties: {
|
|
549
|
+
expeditions: omit(findByIds(), 'title'),
|
|
550
|
+
driver: driver(),
|
|
551
|
+
},
|
|
552
|
+
required: ['expeditions', 'driver'],
|
|
553
|
+
additionalProperties: false,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const processExpeditionsWithCustomerRequest = () => ({
|
|
557
|
+
type: 'object',
|
|
558
|
+
properties: {
|
|
559
|
+
expeditions: omit(findByIds(), 'title'),
|
|
560
|
+
customer: customerWithPod(),
|
|
561
|
+
},
|
|
562
|
+
required: ['expeditions', 'customer'],
|
|
563
|
+
additionalProperties: false,
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
const processExpeditionResultOk = () => mergeSchemas(objectWithUuid(), resultOk());
|
|
567
|
+
|
|
568
|
+
const processExpeditionResultNotFound = () => mergeSchemas(objectWithUuid(), resultNotFound());
|
|
569
|
+
|
|
570
|
+
const processExpeditionResultAnotherSituation = () => mergeSchemas(objectWithUuid(), resultAnotherSituation());
|
|
571
|
+
|
|
572
|
+
const processExpeditionResultAnotherShop = () => mergeSchemas(objectWithUuid(), resultAnotherShop());
|
|
573
|
+
|
|
574
|
+
const processExpeditionResultAnotherError = () => mergeSchemas(objectWithUuid(), resultError());
|
|
575
|
+
|
|
576
|
+
const processExpeditionsResponse = () => ({
|
|
577
|
+
type: 'object',
|
|
578
|
+
properties: {
|
|
579
|
+
expeditions: {
|
|
580
|
+
type: 'array',
|
|
581
|
+
items: {
|
|
582
|
+
oneOf: [
|
|
583
|
+
processExpeditionResultOk(),
|
|
584
|
+
processExpeditionResultNotFound(),
|
|
585
|
+
processExpeditionResultAnotherSituation(),
|
|
586
|
+
processExpeditionResultAnotherShop(),
|
|
587
|
+
processExpeditionResultAnotherError(),
|
|
588
|
+
],
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
required: ['expeditions'],
|
|
593
|
+
additionalProperties: false,
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
const receiveAllExpeditionsFromDriverRequest = () => ({
|
|
597
|
+
type: 'object',
|
|
598
|
+
properties: {
|
|
599
|
+
driver: driver(),
|
|
600
|
+
},
|
|
601
|
+
required: ['driver'],
|
|
602
|
+
additionalProperties: false,
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
const receiveAllExpeditionsFromDriverResponse = () => ({
|
|
606
|
+
type: 'object',
|
|
607
|
+
properties: {
|
|
608
|
+
expeditions: { type: 'integer', minimum: 0 },
|
|
609
|
+
},
|
|
610
|
+
required: ['expeditions'],
|
|
611
|
+
additionalProperties: false,
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
module.exports = {
|
|
615
|
+
processedWithDriver,
|
|
616
|
+
processedWithCustomer,
|
|
617
|
+
processedWithCustomerWithPod,
|
|
618
|
+
expedition,
|
|
619
|
+
objectWithExpeditionId,
|
|
620
|
+
createExpeditionRequest,
|
|
621
|
+
createExpeditionResponse,
|
|
622
|
+
findExpeditionsRequest,
|
|
623
|
+
findExpeditionsResponse,
|
|
624
|
+
updateExpeditionRequest,
|
|
625
|
+
updateExpeditionResponse,
|
|
626
|
+
deleteExpeditionRequest,
|
|
627
|
+
deleteExpeditionResponse,
|
|
628
|
+
redirectExpeditionRequest,
|
|
629
|
+
redirectExpeditionResponse,
|
|
630
|
+
scanExpeditionRequest,
|
|
631
|
+
scanExpeditionResponse,
|
|
632
|
+
processExpeditionsWithDriverRequest,
|
|
633
|
+
processExpeditionsWithCustomerRequest,
|
|
634
|
+
processExpeditionsResponse,
|
|
635
|
+
receiveAllExpeditionsFromDriverRequest,
|
|
636
|
+
receiveAllExpeditionsFromDriverResponse,
|
|
637
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { password } = require('@gls_spain/common-json-schemas');
|
|
2
|
+
const { superAdmin } = require('./users');
|
|
3
|
+
const { defaults } = require('./defaults');
|
|
4
|
+
|
|
5
|
+
const initRequest = () => ({
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
superAdmin: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
username: superAdmin().properties.username,
|
|
12
|
+
password: password(),
|
|
13
|
+
},
|
|
14
|
+
required: ['username', 'password'],
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
},
|
|
17
|
+
defaults: defaults(),
|
|
18
|
+
},
|
|
19
|
+
required: ['superAdmin', 'defaults'],
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const initResponse = () => ({
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
superAdmin: superAdmin(),
|
|
27
|
+
defaults: defaults(),
|
|
28
|
+
indexes: { type: 'array', items: { type: 'string' } },
|
|
29
|
+
},
|
|
30
|
+
required: ['superAdmin', 'defaults', 'indexes'],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
initRequest,
|
|
36
|
+
initResponse,
|
|
37
|
+
};
|