@gls_spain/gps-common 34.9.2 → 34.9.4
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 +1271 -1257
- 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 -451
- 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 +413 -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 -699
|
@@ -1,867 +1,867 @@
|
|
|
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, findByOptionalDateRange } = require('./common');
|
|
21
|
-
const { address } = require('./common');
|
|
22
|
-
const { network, objectWithNetworkId } = 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', trim: true },
|
|
38
|
-
contact: { type: 'string', trim: true },
|
|
39
|
-
department: { 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
|
-
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', trim: true },
|
|
55
|
-
code: { type: 'string', trim: true },
|
|
56
|
-
device: { type: 'string', trim: true },
|
|
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', trim: true },
|
|
67
|
-
nif: { type: 'string', trim: true },
|
|
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', trim: true },
|
|
78
|
-
nif: { type: 'string', trim: true },
|
|
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']) },
|
|
129
|
-
required: ['_id', 'name'],
|
|
130
|
-
additionalProperties: false,
|
|
131
|
-
},
|
|
132
|
-
otherNetworks: {
|
|
133
|
-
type: 'array',
|
|
134
|
-
items: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
137
|
-
required: ['_id', 'name'],
|
|
138
|
-
additionalProperties: false,
|
|
139
|
-
},
|
|
140
|
-
minItems: 1,
|
|
141
|
-
uniqueItems: true,
|
|
142
|
-
description: `only for incoming expeditions created with multiple networks and no shop, on reception this field is removed and \`network\` and \`shop\` set to the receiving shop`,
|
|
143
|
-
},
|
|
144
|
-
shop: {
|
|
145
|
-
type: 'object',
|
|
146
|
-
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
147
|
-
required: ['_id', 'name'],
|
|
148
|
-
additionalProperties: false,
|
|
149
|
-
description: 'not available for incoming expeditions created with no shop, on reception this will be set to the receiving shop',
|
|
150
|
-
},
|
|
151
|
-
type: { type: 'string', enum: ['delivery', 'pickup'] },
|
|
152
|
-
status: {
|
|
153
|
-
type: 'object',
|
|
154
|
-
properties: {
|
|
155
|
-
code: { type: 'string', enum: ['incoming', 'inShop', 'inShopExpired', 'delivered'] },
|
|
156
|
-
receivedFrom: {
|
|
157
|
-
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
158
|
-
description: 'how and when did the expedition enter the shop, only available for status inShop or later',
|
|
159
|
-
},
|
|
160
|
-
givenTo: {
|
|
161
|
-
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
162
|
-
description: 'how and when did the expedition leave the shop, only available for status delivered',
|
|
163
|
-
},
|
|
164
|
-
expiration: {
|
|
165
|
-
type: 'object',
|
|
166
|
-
properties: {
|
|
167
|
-
expirationDate: date(),
|
|
168
|
-
expirationAt: datetime(),
|
|
169
|
-
pendingReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
170
|
-
sentReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
171
|
-
},
|
|
172
|
-
required: ['expirationDate', 'expirationAt', 'pendingReminders', 'sentReminders'],
|
|
173
|
-
additionalProperties: false,
|
|
174
|
-
description: 'when will the expedition expire, only available for deliveries and pickups after reception at the shop',
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
required: ['code'],
|
|
178
|
-
additionalProperties: false,
|
|
179
|
-
},
|
|
180
|
-
code: { type: 'integer', description: 'GLS codexp' },
|
|
181
|
-
serviceCode: { type: 'integer' },
|
|
182
|
-
scheduleCode: { type: 'integer' },
|
|
183
|
-
date: { type: 'string', format: 'date' },
|
|
184
|
-
expectedDeliveryDate: { type: 'string', format: 'date' },
|
|
185
|
-
derivation: {
|
|
186
|
-
type: 'object',
|
|
187
|
-
properties: {
|
|
188
|
-
totalPrice: {
|
|
189
|
-
type: 'object',
|
|
190
|
-
properties: {
|
|
191
|
-
network: { ...money(), description: 'total amount paid to the network, in cents' },
|
|
192
|
-
shop: { ...money(), description: 'total amount paid to the shop, in cents' },
|
|
193
|
-
},
|
|
194
|
-
required: ['network', 'shop'],
|
|
195
|
-
additionalProperties: false,
|
|
196
|
-
},
|
|
197
|
-
settings: derivationSettings(),
|
|
198
|
-
},
|
|
199
|
-
required: ['totalPrice', 'settings'],
|
|
200
|
-
additionalProperties: false,
|
|
201
|
-
description: 'only available for deliveries and pickups after reception at the shop',
|
|
202
|
-
},
|
|
203
|
-
sale: mergeSchemas(objectWithUuid(), { description: 'associated sale, only for expeditions created because of a sale' }),
|
|
204
|
-
barcodes: { type: 'array', items: { type: 'string', trim: true } },
|
|
205
|
-
packageCount: { type: 'integer' },
|
|
206
|
-
weight: { type: 'number' },
|
|
207
|
-
volume: { type: 'number' },
|
|
208
|
-
origin: expeditionAddress(),
|
|
209
|
-
destination: expeditionAddress(),
|
|
210
|
-
sender: expeditionAddress(),
|
|
211
|
-
agency: {
|
|
212
|
-
title: 'expedition agency',
|
|
213
|
-
type: 'object',
|
|
214
|
-
properties: {
|
|
215
|
-
code: { type: 'integer' },
|
|
216
|
-
name: { type: 'string', trim: true },
|
|
217
|
-
contact: { type: 'string', trim: true },
|
|
218
|
-
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
219
|
-
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
220
|
-
openingSchedule: { type: 'string', trim: true },
|
|
221
|
-
},
|
|
222
|
-
required: ['code', 'name', 'emails', 'phones'],
|
|
223
|
-
additionalProperties: false,
|
|
224
|
-
},
|
|
225
|
-
client: {
|
|
226
|
-
title: 'expedition client',
|
|
227
|
-
type: 'object',
|
|
228
|
-
properties: {
|
|
229
|
-
code: { type: 'integer' },
|
|
230
|
-
name: { type: 'string', trim: true },
|
|
231
|
-
agency: objectWithAgencyCode(),
|
|
232
|
-
},
|
|
233
|
-
required: ['code', 'name', 'agency'],
|
|
234
|
-
additionalProperties: false,
|
|
235
|
-
},
|
|
236
|
-
references: {
|
|
237
|
-
type: 'array',
|
|
238
|
-
items: {
|
|
239
|
-
title: 'expedition reference',
|
|
240
|
-
type: 'object',
|
|
241
|
-
properties: {
|
|
242
|
-
type: { type: 'string', trim: true },
|
|
243
|
-
value: { type: 'string', trim: true },
|
|
244
|
-
},
|
|
245
|
-
required: ['type', 'value'],
|
|
246
|
-
additionalProperties: false,
|
|
247
|
-
description: 'may have duplicates',
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
packages: {
|
|
251
|
-
type: 'array',
|
|
252
|
-
items: {
|
|
253
|
-
title: 'expedition package',
|
|
254
|
-
type: 'object',
|
|
255
|
-
properties: {
|
|
256
|
-
number: { type: 'integer', description: 'package number in expedition (1, 2, 3), can be sparse' },
|
|
257
|
-
barcodes: { type: 'array', items: { type: 'string', trim: true } },
|
|
258
|
-
weight: { type: 'number' },
|
|
259
|
-
width: { type: 'number' },
|
|
260
|
-
length: { type: 'number' },
|
|
261
|
-
height: { type: 'number' },
|
|
262
|
-
},
|
|
263
|
-
required: ['number', 'barcodes'],
|
|
264
|
-
additionalProperties: false,
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
notes: { type: 'string', trim: true },
|
|
268
|
-
},
|
|
269
|
-
required: [
|
|
270
|
-
'_id',
|
|
271
|
-
'createdAt',
|
|
272
|
-
'updatedAt',
|
|
273
|
-
'deletable',
|
|
274
|
-
'network',
|
|
275
|
-
'type',
|
|
276
|
-
'status',
|
|
277
|
-
'code',
|
|
278
|
-
'serviceCode',
|
|
279
|
-
'scheduleCode',
|
|
280
|
-
'date',
|
|
281
|
-
'expectedDeliveryDate',
|
|
282
|
-
'barcodes',
|
|
283
|
-
'packageCount',
|
|
284
|
-
'weight',
|
|
285
|
-
'origin',
|
|
286
|
-
'destination',
|
|
287
|
-
'sender',
|
|
288
|
-
'agency',
|
|
289
|
-
'client',
|
|
290
|
-
'references',
|
|
291
|
-
'packages',
|
|
292
|
-
],
|
|
293
|
-
additionalProperties: false,
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
const objectWithExpeditionId = () => ({
|
|
297
|
-
type: 'object',
|
|
298
|
-
properties: { expedition: objectWithUuid() },
|
|
299
|
-
required: ['expedition'],
|
|
300
|
-
additionalProperties: false,
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const createExpeditionWithShop = () => ({
|
|
304
|
-
title: 'create with shop',
|
|
305
|
-
type: 'object',
|
|
306
|
-
properties: {
|
|
307
|
-
...pickProperties(expedition(), ['_id', 'createdAt']),
|
|
308
|
-
shop: objectWithUuid(),
|
|
309
|
-
...pickProperties(expedition(), [
|
|
310
|
-
'type',
|
|
311
|
-
'code',
|
|
312
|
-
'serviceCode',
|
|
313
|
-
'scheduleCode',
|
|
314
|
-
'date',
|
|
315
|
-
'expectedDeliveryDate',
|
|
316
|
-
'sale',
|
|
317
|
-
'barcodes',
|
|
318
|
-
'packageCount',
|
|
319
|
-
'weight',
|
|
320
|
-
'volume',
|
|
321
|
-
'origin',
|
|
322
|
-
'destination',
|
|
323
|
-
'sender',
|
|
324
|
-
'agency',
|
|
325
|
-
'client',
|
|
326
|
-
'references',
|
|
327
|
-
'packages',
|
|
328
|
-
'notes',
|
|
329
|
-
]),
|
|
330
|
-
},
|
|
331
|
-
required: [
|
|
332
|
-
'shop',
|
|
333
|
-
'type',
|
|
334
|
-
'code',
|
|
335
|
-
'serviceCode',
|
|
336
|
-
'scheduleCode',
|
|
337
|
-
'date',
|
|
338
|
-
'expectedDeliveryDate',
|
|
339
|
-
'packageCount',
|
|
340
|
-
'weight',
|
|
341
|
-
'origin',
|
|
342
|
-
'destination',
|
|
343
|
-
'sender',
|
|
344
|
-
'agency',
|
|
345
|
-
'client',
|
|
346
|
-
],
|
|
347
|
-
additionalProperties: false,
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const createExpeditionWithNetwork = () => ({
|
|
351
|
-
title: 'create with one or more networks',
|
|
352
|
-
type: 'object',
|
|
353
|
-
properties: {
|
|
354
|
-
...pickProperties(expedition(), ['_id', 'createdAt']),
|
|
355
|
-
network: mergeSchemas(objectWithUuid(), {
|
|
356
|
-
description: `any shop in the network can receive it, on reception \`shop\` will be set to the receiving shop`,
|
|
357
|
-
}),
|
|
358
|
-
otherNetworks: {
|
|
359
|
-
type: 'array',
|
|
360
|
-
items: objectWithUuid(),
|
|
361
|
-
minItems: 1,
|
|
362
|
-
uniqueItems: true,
|
|
363
|
-
description: `additional networks the expedition can be received in, on reception this will be removed and \`network\` and \`shop\` set to the receiving shop`,
|
|
364
|
-
},
|
|
365
|
-
...pickProperties(expedition(), [
|
|
366
|
-
'type',
|
|
367
|
-
'code',
|
|
368
|
-
'serviceCode',
|
|
369
|
-
'scheduleCode',
|
|
370
|
-
'date',
|
|
371
|
-
'expectedDeliveryDate',
|
|
372
|
-
'barcodes',
|
|
373
|
-
'packageCount',
|
|
374
|
-
'weight',
|
|
375
|
-
'volume',
|
|
376
|
-
'origin',
|
|
377
|
-
'destination',
|
|
378
|
-
'sender',
|
|
379
|
-
'agency',
|
|
380
|
-
'client',
|
|
381
|
-
'references',
|
|
382
|
-
'packages',
|
|
383
|
-
'notes',
|
|
384
|
-
]),
|
|
385
|
-
},
|
|
386
|
-
required: [
|
|
387
|
-
'network',
|
|
388
|
-
'type',
|
|
389
|
-
'code',
|
|
390
|
-
'serviceCode',
|
|
391
|
-
'scheduleCode',
|
|
392
|
-
'date',
|
|
393
|
-
'expectedDeliveryDate',
|
|
394
|
-
'packageCount',
|
|
395
|
-
'weight',
|
|
396
|
-
'origin',
|
|
397
|
-
'destination',
|
|
398
|
-
'sender',
|
|
399
|
-
'agency',
|
|
400
|
-
'client',
|
|
401
|
-
],
|
|
402
|
-
additionalProperties: false,
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
const createExpeditionRequest = () => createRequest({ oneOf: [createExpeditionWithShop(), createExpeditionWithNetwork()] });
|
|
406
|
-
|
|
407
|
-
const createExpeditionResponse = () => createResponse(expedition());
|
|
408
|
-
|
|
409
|
-
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
410
|
-
|
|
411
|
-
const findByNoShop = () => ({
|
|
412
|
-
title: 'find by no shop',
|
|
413
|
-
type: 'object',
|
|
414
|
-
properties: { shop: { type: 'null' } },
|
|
415
|
-
required: ['shop'],
|
|
416
|
-
additionalProperties: false,
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
const findByStatus = () => ({
|
|
420
|
-
title: 'find by status',
|
|
421
|
-
type: 'object',
|
|
422
|
-
properties: {
|
|
423
|
-
status: {
|
|
424
|
-
type: 'object',
|
|
425
|
-
properties: { code: expedition().properties.status.properties.code },
|
|
426
|
-
required: ['code'],
|
|
427
|
-
additionalProperties: false,
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
required: ['status'],
|
|
431
|
-
additionalProperties: false,
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
const findByShopAndTypesAndStatus = () =>
|
|
435
|
-
mergeSchemas(findByShop(), {
|
|
436
|
-
title: 'find by shop and types and status',
|
|
437
|
-
type: 'object',
|
|
438
|
-
properties: {
|
|
439
|
-
typesAndStatus: {
|
|
440
|
-
type: 'array',
|
|
441
|
-
items: {
|
|
442
|
-
type: 'object',
|
|
443
|
-
properties: {
|
|
444
|
-
type: expedition().properties.type,
|
|
445
|
-
status: {
|
|
446
|
-
type: 'object',
|
|
447
|
-
properties: { code: expedition().properties.status.properties.code },
|
|
448
|
-
required: ['code'],
|
|
449
|
-
additionalProperties: false,
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
required: ['type', 'status'],
|
|
453
|
-
additionalProperties: false,
|
|
454
|
-
},
|
|
455
|
-
uniqueItems: true,
|
|
456
|
-
minItems: 1,
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
required: ['typesAndStatus'],
|
|
460
|
-
additionalProperties: false,
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
const findByShopAndStatus = () => mergeSchemas(findByShop(), findByStatus(), { title: 'find by shop and status' });
|
|
464
|
-
|
|
465
|
-
const findByNoShopAndStatus = () => mergeSchemas(findByNoShop(), findByStatus(), { title: 'find by no shop and status' });
|
|
466
|
-
|
|
467
|
-
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
468
|
-
|
|
469
|
-
const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
|
|
470
|
-
|
|
471
|
-
const findByNetworkAndNoShop = () => mergeSchemas(findByNetwork(), findByNoShop(), { title: 'find by network and no shop' });
|
|
472
|
-
|
|
473
|
-
const findByNetworkAndNoShopAndStatus = () =>
|
|
474
|
-
mergeSchemas(findByNetworkAndNoShop(), findByStatus(), { title: 'find by network and no shop and status' });
|
|
475
|
-
|
|
476
|
-
const findByCode = () => ({
|
|
477
|
-
title: 'find by code',
|
|
478
|
-
type: 'object',
|
|
479
|
-
properties: {
|
|
480
|
-
code: expedition().properties.code,
|
|
481
|
-
},
|
|
482
|
-
required: ['code'],
|
|
483
|
-
additionalProperties: false,
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
const findBySale = () => ({
|
|
487
|
-
title: 'find by sale',
|
|
488
|
-
type: 'object',
|
|
489
|
-
properties: {
|
|
490
|
-
sale: objectWithUuid(),
|
|
491
|
-
},
|
|
492
|
-
required: ['sale'],
|
|
493
|
-
additionalProperties: false,
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
const findExpeditionsSuperAdminRequest = () =>
|
|
497
|
-
findRequest({
|
|
498
|
-
oneOf: [
|
|
499
|
-
findById(),
|
|
500
|
-
mergeSchemas(findByNetwork(), findByOptionalDateRange()),
|
|
501
|
-
mergeSchemas(findByNetworkAndStatus(), findByOptionalDateRange()),
|
|
502
|
-
mergeSchemas(findByNetworkAndNoShop(), findByOptionalDateRange()),
|
|
503
|
-
mergeSchemas(findByNetworkAndNoShopAndStatus(), findByOptionalDateRange()),
|
|
504
|
-
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
505
|
-
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
506
|
-
findByCode(),
|
|
507
|
-
findBySale(),
|
|
508
|
-
],
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
const findExpeditionsNetworkAdminRequest = () =>
|
|
512
|
-
findRequest({
|
|
513
|
-
oneOf: [
|
|
514
|
-
findById(),
|
|
515
|
-
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
516
|
-
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
517
|
-
mergeSchemas(findByNoShop(), findByOptionalDateRange()),
|
|
518
|
-
mergeSchemas(findByNoShopAndStatus(), findByOptionalDateRange()),
|
|
519
|
-
findByCode(),
|
|
520
|
-
findBySale(),
|
|
521
|
-
],
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
const findExpeditionsShopUserRequest = () =>
|
|
525
|
-
findRequest({
|
|
526
|
-
oneOf: [
|
|
527
|
-
findById(),
|
|
528
|
-
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
529
|
-
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
530
|
-
mergeSchemas(findByShopAndTypesAndStatus(), findByOptionalDateRange()),
|
|
531
|
-
mergeSchemas(findByNoShop(), findByOptionalDateRange()),
|
|
532
|
-
mergeSchemas(findByNoShopAndStatus(), findByOptionalDateRange()),
|
|
533
|
-
findByCode(),
|
|
534
|
-
findBySale(),
|
|
535
|
-
],
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
const findExpeditionsResponse = () => findResponse(expedition());
|
|
539
|
-
|
|
540
|
-
const updateExpeditionRequest = () =>
|
|
541
|
-
updateRequest(
|
|
542
|
-
findById(),
|
|
543
|
-
{
|
|
544
|
-
type: 'object',
|
|
545
|
-
properties: {
|
|
546
|
-
...pickProperties(
|
|
547
|
-
expedition(),
|
|
548
|
-
[
|
|
549
|
-
'code',
|
|
550
|
-
'serviceCode',
|
|
551
|
-
'scheduleCode',
|
|
552
|
-
'date',
|
|
553
|
-
'expectedDeliveryDate',
|
|
554
|
-
'barcodes',
|
|
555
|
-
'packageCount',
|
|
556
|
-
'weight',
|
|
557
|
-
'origin',
|
|
558
|
-
'destination',
|
|
559
|
-
'sender',
|
|
560
|
-
'agency',
|
|
561
|
-
'client',
|
|
562
|
-
'references',
|
|
563
|
-
'packages',
|
|
564
|
-
],
|
|
565
|
-
['volume', 'notes'],
|
|
566
|
-
),
|
|
567
|
-
},
|
|
568
|
-
minProperties: 1,
|
|
569
|
-
additionalProperties: false,
|
|
570
|
-
},
|
|
571
|
-
{
|
|
572
|
-
type: 'object',
|
|
573
|
-
properties: { ...pickProperties(expedition(), ['barcodes', 'references']) },
|
|
574
|
-
minProperties: 1,
|
|
575
|
-
additionalProperties: false,
|
|
576
|
-
},
|
|
577
|
-
);
|
|
578
|
-
|
|
579
|
-
const updateExpeditionResponse = () => updateResponse(expedition());
|
|
580
|
-
|
|
581
|
-
const deleteExpeditionRequest = () => deleteRequest(findById());
|
|
582
|
-
|
|
583
|
-
const deleteExpeditionResponse = () => deleteResponse(expedition());
|
|
584
|
-
|
|
585
|
-
const redirectExpeditionRequest = () => ({
|
|
586
|
-
type: 'object',
|
|
587
|
-
properties: {
|
|
588
|
-
find: findById(),
|
|
589
|
-
redirect: objectWithShopId(),
|
|
590
|
-
},
|
|
591
|
-
required: ['find', 'redirect'],
|
|
592
|
-
additionalProperties: false,
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
const redirectExpeditionResponse = () => ({
|
|
596
|
-
type: 'object',
|
|
597
|
-
properties: { redirected: expedition() },
|
|
598
|
-
required: ['redirected'],
|
|
599
|
-
additionalProperties: false,
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
const objectWithTypeAndStatus = () => ({
|
|
603
|
-
type: 'object',
|
|
604
|
-
properties: {
|
|
605
|
-
type: expedition().properties.type,
|
|
606
|
-
status: {
|
|
607
|
-
type: 'object',
|
|
608
|
-
properties: { code: expedition().properties.status.properties.code },
|
|
609
|
-
required: ['code'],
|
|
610
|
-
additionalProperties: false,
|
|
611
|
-
},
|
|
612
|
-
},
|
|
613
|
-
required: ['type', 'status'],
|
|
614
|
-
additionalProperties: false,
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
const scanExpeditionRequest = () => ({
|
|
618
|
-
type: 'object',
|
|
619
|
-
properties: {
|
|
620
|
-
scan: {
|
|
621
|
-
oneOf: [
|
|
622
|
-
{
|
|
623
|
-
title: 'barcode',
|
|
624
|
-
type: 'object',
|
|
625
|
-
properties: { barcode: { type: 'string', trim: true } },
|
|
626
|
-
required: ['barcode'],
|
|
627
|
-
additionalProperties: false,
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
title: 'QR code',
|
|
631
|
-
type: 'object',
|
|
632
|
-
properties: { qrCode: { type: 'string', trim: true } },
|
|
633
|
-
required: ['qrCode'],
|
|
634
|
-
additionalProperties: false,
|
|
635
|
-
},
|
|
636
|
-
],
|
|
637
|
-
},
|
|
638
|
-
},
|
|
639
|
-
required: ['scan'],
|
|
640
|
-
additionalProperties: false,
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
const resultOk = () => ({
|
|
644
|
-
title: 'ok',
|
|
645
|
-
type: 'object',
|
|
646
|
-
properties: { ok: expedition() },
|
|
647
|
-
required: ['ok'],
|
|
648
|
-
additionalProperties: false,
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
const resultNotFound = () => ({
|
|
652
|
-
title: 'not found',
|
|
653
|
-
type: 'object',
|
|
654
|
-
properties: { notFound: { type: 'boolean', enum: [true] } },
|
|
655
|
-
required: ['notFound'],
|
|
656
|
-
additionalProperties: false,
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
const resultAnotherSituation = () => ({
|
|
660
|
-
title: 'another situation',
|
|
661
|
-
type: 'object',
|
|
662
|
-
properties: { anotherSituation: objectWithTypeAndStatus() },
|
|
663
|
-
required: ['anotherSituation'],
|
|
664
|
-
additionalProperties: false,
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
const resultAnotherShop = () => ({
|
|
668
|
-
title: 'another shop',
|
|
669
|
-
type: 'object',
|
|
670
|
-
properties: {
|
|
671
|
-
anotherShop: {
|
|
672
|
-
type: 'object',
|
|
673
|
-
properties: { ...pickProperties(shop(), ['name']) },
|
|
674
|
-
required: ['name'],
|
|
675
|
-
additionalProperties: false,
|
|
676
|
-
},
|
|
677
|
-
},
|
|
678
|
-
required: ['anotherShop'],
|
|
679
|
-
additionalProperties: false,
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
const resultMultipleResults = () => ({
|
|
683
|
-
title: 'multiple results',
|
|
684
|
-
type: 'object',
|
|
685
|
-
properties: { multipleResults: { type: 'boolean', enum: [true] } },
|
|
686
|
-
required: ['multipleResults'],
|
|
687
|
-
additionalProperties: false,
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
const resultError = () => ({
|
|
691
|
-
title: 'error',
|
|
692
|
-
type: 'object',
|
|
693
|
-
properties: { error: { type: 'string' } },
|
|
694
|
-
required: ['error'],
|
|
695
|
-
additionalProperties: false,
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
const scanExpeditionResponse = () => ({
|
|
699
|
-
oneOf: [resultOk(), resultNotFound(), resultAnotherShop(), resultMultipleResults(), resultError()],
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
const processExpeditionsWithDriverRequest = () => ({
|
|
703
|
-
type: 'object',
|
|
704
|
-
properties: {
|
|
705
|
-
expeditions: omit(findByIds(), 'title'),
|
|
706
|
-
driver: driver(),
|
|
707
|
-
},
|
|
708
|
-
required: ['expeditions', 'driver'],
|
|
709
|
-
additionalProperties: false,
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
const processExpeditionsWithCustomerRequest = () => ({
|
|
713
|
-
type: 'object',
|
|
714
|
-
properties: {
|
|
715
|
-
expeditions: omit(findByIds(), 'title'),
|
|
716
|
-
customer: customerWithPod(),
|
|
717
|
-
},
|
|
718
|
-
required: ['expeditions', 'customer'],
|
|
719
|
-
additionalProperties: false,
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
const processExpeditionResultOk = () => mergeSchemas(objectWithUuid(), resultOk());
|
|
723
|
-
|
|
724
|
-
const processExpeditionResultNotFound = () => mergeSchemas(objectWithUuid(), resultNotFound());
|
|
725
|
-
|
|
726
|
-
const processExpeditionResultAnotherSituation = () => mergeSchemas(objectWithUuid(), resultAnotherSituation());
|
|
727
|
-
|
|
728
|
-
const processExpeditionResultAnotherShop = () => mergeSchemas(objectWithUuid(), resultAnotherShop());
|
|
729
|
-
|
|
730
|
-
const processExpeditionResultAnotherError = () => mergeSchemas(objectWithUuid(), resultError());
|
|
731
|
-
|
|
732
|
-
const processExpeditionsResponse = () => ({
|
|
733
|
-
type: 'object',
|
|
734
|
-
properties: {
|
|
735
|
-
expeditions: {
|
|
736
|
-
type: 'array',
|
|
737
|
-
items: {
|
|
738
|
-
oneOf: [
|
|
739
|
-
processExpeditionResultOk(),
|
|
740
|
-
processExpeditionResultNotFound(),
|
|
741
|
-
processExpeditionResultAnotherSituation(),
|
|
742
|
-
processExpeditionResultAnotherShop(),
|
|
743
|
-
processExpeditionResultAnotherError(),
|
|
744
|
-
],
|
|
745
|
-
},
|
|
746
|
-
},
|
|
747
|
-
},
|
|
748
|
-
required: ['expeditions'],
|
|
749
|
-
additionalProperties: false,
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
const receiveAllExpeditionsFromDriverRequest = () => ({
|
|
753
|
-
type: 'object',
|
|
754
|
-
properties: {
|
|
755
|
-
driver: driver(),
|
|
756
|
-
},
|
|
757
|
-
required: ['driver'],
|
|
758
|
-
additionalProperties: false,
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
const receiveAllExpeditionsFromDriverResponse = () => ({
|
|
762
|
-
type: 'object',
|
|
763
|
-
properties: {
|
|
764
|
-
expeditions: { type: 'integer', minimum: 0 },
|
|
765
|
-
},
|
|
766
|
-
required: ['expeditions'],
|
|
767
|
-
additionalProperties: false,
|
|
768
|
-
});
|
|
769
|
-
|
|
770
|
-
const downloadExpeditionLabelRequest = () => ({
|
|
771
|
-
type: 'object',
|
|
772
|
-
properties: {
|
|
773
|
-
download: objectWithUuid(),
|
|
774
|
-
},
|
|
775
|
-
required: ['download'],
|
|
776
|
-
additionalProperties: false,
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
const downloadExpeditionLabelResponse = () => ({
|
|
780
|
-
type: 'object',
|
|
781
|
-
properties: {
|
|
782
|
-
download: {
|
|
783
|
-
type: 'object',
|
|
784
|
-
properties: {
|
|
785
|
-
label: { type: 'string', description: 'a PDF file encoded as a Base64 string' },
|
|
786
|
-
},
|
|
787
|
-
required: ['label'],
|
|
788
|
-
additionalProperties: false,
|
|
789
|
-
},
|
|
790
|
-
},
|
|
791
|
-
required: ['download'],
|
|
792
|
-
additionalProperties: false,
|
|
793
|
-
});
|
|
794
|
-
|
|
795
|
-
const expireExpeditionRequest = () => ({
|
|
796
|
-
type: 'object',
|
|
797
|
-
properties: {
|
|
798
|
-
expire: objectWithUuid(),
|
|
799
|
-
},
|
|
800
|
-
required: ['expire'],
|
|
801
|
-
additionalProperties: false,
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
const unexpireExpeditionRequest = () => ({
|
|
805
|
-
type: 'object',
|
|
806
|
-
properties: {
|
|
807
|
-
unexpire: objectWithUuid(),
|
|
808
|
-
},
|
|
809
|
-
required: ['unexpire'],
|
|
810
|
-
additionalProperties: false,
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
const updateExpeditionDerivationRequest = () => ({
|
|
814
|
-
type: 'object',
|
|
815
|
-
properties: {
|
|
816
|
-
find: objectWithUuid(),
|
|
817
|
-
set: {
|
|
818
|
-
type: 'object',
|
|
819
|
-
properties: {
|
|
820
|
-
derivation: {
|
|
821
|
-
type: 'object',
|
|
822
|
-
properties: {
|
|
823
|
-
settings: derivationSettings(),
|
|
824
|
-
},
|
|
825
|
-
required: ['settings'],
|
|
826
|
-
additionalProperties: false,
|
|
827
|
-
},
|
|
828
|
-
},
|
|
829
|
-
required: ['derivation'],
|
|
830
|
-
additionalProperties: false,
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
required: ['find', 'set'],
|
|
834
|
-
additionalProperties: false,
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
module.exports = {
|
|
838
|
-
processedWithDriver,
|
|
839
|
-
processedWithCustomer,
|
|
840
|
-
processedWithCustomerWithPod,
|
|
841
|
-
expedition,
|
|
842
|
-
objectWithExpeditionId,
|
|
843
|
-
createExpeditionRequest,
|
|
844
|
-
createExpeditionResponse,
|
|
845
|
-
findExpeditionsSuperAdminRequest,
|
|
846
|
-
findExpeditionsNetworkAdminRequest,
|
|
847
|
-
findExpeditionsShopUserRequest,
|
|
848
|
-
findExpeditionsResponse,
|
|
849
|
-
updateExpeditionRequest,
|
|
850
|
-
updateExpeditionResponse,
|
|
851
|
-
deleteExpeditionRequest,
|
|
852
|
-
deleteExpeditionResponse,
|
|
853
|
-
redirectExpeditionRequest,
|
|
854
|
-
redirectExpeditionResponse,
|
|
855
|
-
scanExpeditionRequest,
|
|
856
|
-
scanExpeditionResponse,
|
|
857
|
-
processExpeditionsWithDriverRequest,
|
|
858
|
-
processExpeditionsWithCustomerRequest,
|
|
859
|
-
processExpeditionsResponse,
|
|
860
|
-
receiveAllExpeditionsFromDriverRequest,
|
|
861
|
-
receiveAllExpeditionsFromDriverResponse,
|
|
862
|
-
downloadExpeditionLabelRequest,
|
|
863
|
-
downloadExpeditionLabelResponse,
|
|
864
|
-
expireExpeditionRequest,
|
|
865
|
-
unexpireExpeditionRequest,
|
|
866
|
-
updateExpeditionDerivationRequest,
|
|
867
|
-
};
|
|
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, findByOptionalDateRange } = require('./common');
|
|
21
|
+
const { address } = require('./common');
|
|
22
|
+
const { network, objectWithNetworkId } = 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', trim: true },
|
|
38
|
+
contact: { type: 'string', trim: true },
|
|
39
|
+
department: { 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
|
+
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', trim: true },
|
|
55
|
+
code: { type: 'string', trim: true },
|
|
56
|
+
device: { type: 'string', trim: true },
|
|
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', trim: true },
|
|
67
|
+
nif: { type: 'string', trim: true },
|
|
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', trim: true },
|
|
78
|
+
nif: { type: 'string', trim: true },
|
|
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']) },
|
|
129
|
+
required: ['_id', 'name'],
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
},
|
|
132
|
+
otherNetworks: {
|
|
133
|
+
type: 'array',
|
|
134
|
+
items: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
137
|
+
required: ['_id', 'name'],
|
|
138
|
+
additionalProperties: false,
|
|
139
|
+
},
|
|
140
|
+
minItems: 1,
|
|
141
|
+
uniqueItems: true,
|
|
142
|
+
description: `only for incoming expeditions created with multiple networks and no shop, on reception this field is removed and \`network\` and \`shop\` set to the receiving shop`,
|
|
143
|
+
},
|
|
144
|
+
shop: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
147
|
+
required: ['_id', 'name'],
|
|
148
|
+
additionalProperties: false,
|
|
149
|
+
description: 'not available for incoming expeditions created with no shop, on reception this will be set to the receiving shop',
|
|
150
|
+
},
|
|
151
|
+
type: { type: 'string', enum: ['delivery', 'pickup'] },
|
|
152
|
+
status: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
code: { type: 'string', enum: ['incoming', 'inShop', 'inShopExpired', 'delivered'] },
|
|
156
|
+
receivedFrom: {
|
|
157
|
+
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
158
|
+
description: 'how and when did the expedition enter the shop, only available for status inShop or later',
|
|
159
|
+
},
|
|
160
|
+
givenTo: {
|
|
161
|
+
oneOf: [processedWithDriver(), processedWithCustomer()],
|
|
162
|
+
description: 'how and when did the expedition leave the shop, only available for status delivered',
|
|
163
|
+
},
|
|
164
|
+
expiration: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
expirationDate: date(),
|
|
168
|
+
expirationAt: datetime(),
|
|
169
|
+
pendingReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
170
|
+
sentReminders: { type: 'array', items: datetime(), uniqueItems: true },
|
|
171
|
+
},
|
|
172
|
+
required: ['expirationDate', 'expirationAt', 'pendingReminders', 'sentReminders'],
|
|
173
|
+
additionalProperties: false,
|
|
174
|
+
description: 'when will the expedition expire, only available for deliveries and pickups after reception at the shop',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
required: ['code'],
|
|
178
|
+
additionalProperties: false,
|
|
179
|
+
},
|
|
180
|
+
code: { type: 'integer', description: 'GLS codexp' },
|
|
181
|
+
serviceCode: { type: 'integer' },
|
|
182
|
+
scheduleCode: { type: 'integer' },
|
|
183
|
+
date: { type: 'string', format: 'date' },
|
|
184
|
+
expectedDeliveryDate: { type: 'string', format: 'date' },
|
|
185
|
+
derivation: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
totalPrice: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
properties: {
|
|
191
|
+
network: { ...money(), description: 'total amount paid to the network, in cents' },
|
|
192
|
+
shop: { ...money(), description: 'total amount paid to the shop, in cents' },
|
|
193
|
+
},
|
|
194
|
+
required: ['network', 'shop'],
|
|
195
|
+
additionalProperties: false,
|
|
196
|
+
},
|
|
197
|
+
settings: derivationSettings(),
|
|
198
|
+
},
|
|
199
|
+
required: ['totalPrice', 'settings'],
|
|
200
|
+
additionalProperties: false,
|
|
201
|
+
description: 'only available for deliveries and pickups after reception at the shop',
|
|
202
|
+
},
|
|
203
|
+
sale: mergeSchemas(objectWithUuid(), { description: 'associated sale, only for expeditions created because of a sale' }),
|
|
204
|
+
barcodes: { type: 'array', items: { type: 'string', trim: true } },
|
|
205
|
+
packageCount: { type: 'integer' },
|
|
206
|
+
weight: { type: 'number' },
|
|
207
|
+
volume: { type: 'number' },
|
|
208
|
+
origin: expeditionAddress(),
|
|
209
|
+
destination: expeditionAddress(),
|
|
210
|
+
sender: expeditionAddress(),
|
|
211
|
+
agency: {
|
|
212
|
+
title: 'expedition agency',
|
|
213
|
+
type: 'object',
|
|
214
|
+
properties: {
|
|
215
|
+
code: { type: 'integer' },
|
|
216
|
+
name: { type: 'string', trim: true },
|
|
217
|
+
contact: { type: 'string', trim: true },
|
|
218
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
219
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
220
|
+
openingSchedule: { type: 'string', trim: true },
|
|
221
|
+
},
|
|
222
|
+
required: ['code', 'name', 'emails', 'phones'],
|
|
223
|
+
additionalProperties: false,
|
|
224
|
+
},
|
|
225
|
+
client: {
|
|
226
|
+
title: 'expedition client',
|
|
227
|
+
type: 'object',
|
|
228
|
+
properties: {
|
|
229
|
+
code: { type: 'integer' },
|
|
230
|
+
name: { type: 'string', trim: true },
|
|
231
|
+
agency: objectWithAgencyCode(),
|
|
232
|
+
},
|
|
233
|
+
required: ['code', 'name', 'agency'],
|
|
234
|
+
additionalProperties: false,
|
|
235
|
+
},
|
|
236
|
+
references: {
|
|
237
|
+
type: 'array',
|
|
238
|
+
items: {
|
|
239
|
+
title: 'expedition reference',
|
|
240
|
+
type: 'object',
|
|
241
|
+
properties: {
|
|
242
|
+
type: { type: 'string', trim: true },
|
|
243
|
+
value: { type: 'string', trim: true },
|
|
244
|
+
},
|
|
245
|
+
required: ['type', 'value'],
|
|
246
|
+
additionalProperties: false,
|
|
247
|
+
description: 'may have duplicates',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
packages: {
|
|
251
|
+
type: 'array',
|
|
252
|
+
items: {
|
|
253
|
+
title: 'expedition package',
|
|
254
|
+
type: 'object',
|
|
255
|
+
properties: {
|
|
256
|
+
number: { type: 'integer', description: 'package number in expedition (1, 2, 3), can be sparse' },
|
|
257
|
+
barcodes: { type: 'array', items: { type: 'string', trim: true } },
|
|
258
|
+
weight: { type: 'number' },
|
|
259
|
+
width: { type: 'number' },
|
|
260
|
+
length: { type: 'number' },
|
|
261
|
+
height: { type: 'number' },
|
|
262
|
+
},
|
|
263
|
+
required: ['number', 'barcodes'],
|
|
264
|
+
additionalProperties: false,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
notes: { type: 'string', trim: true },
|
|
268
|
+
},
|
|
269
|
+
required: [
|
|
270
|
+
'_id',
|
|
271
|
+
'createdAt',
|
|
272
|
+
'updatedAt',
|
|
273
|
+
'deletable',
|
|
274
|
+
'network',
|
|
275
|
+
'type',
|
|
276
|
+
'status',
|
|
277
|
+
'code',
|
|
278
|
+
'serviceCode',
|
|
279
|
+
'scheduleCode',
|
|
280
|
+
'date',
|
|
281
|
+
'expectedDeliveryDate',
|
|
282
|
+
'barcodes',
|
|
283
|
+
'packageCount',
|
|
284
|
+
'weight',
|
|
285
|
+
'origin',
|
|
286
|
+
'destination',
|
|
287
|
+
'sender',
|
|
288
|
+
'agency',
|
|
289
|
+
'client',
|
|
290
|
+
'references',
|
|
291
|
+
'packages',
|
|
292
|
+
],
|
|
293
|
+
additionalProperties: false,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const objectWithExpeditionId = () => ({
|
|
297
|
+
type: 'object',
|
|
298
|
+
properties: { expedition: objectWithUuid() },
|
|
299
|
+
required: ['expedition'],
|
|
300
|
+
additionalProperties: false,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const createExpeditionWithShop = () => ({
|
|
304
|
+
title: 'create with shop',
|
|
305
|
+
type: 'object',
|
|
306
|
+
properties: {
|
|
307
|
+
...pickProperties(expedition(), ['_id', 'createdAt']),
|
|
308
|
+
shop: objectWithUuid(),
|
|
309
|
+
...pickProperties(expedition(), [
|
|
310
|
+
'type',
|
|
311
|
+
'code',
|
|
312
|
+
'serviceCode',
|
|
313
|
+
'scheduleCode',
|
|
314
|
+
'date',
|
|
315
|
+
'expectedDeliveryDate',
|
|
316
|
+
'sale',
|
|
317
|
+
'barcodes',
|
|
318
|
+
'packageCount',
|
|
319
|
+
'weight',
|
|
320
|
+
'volume',
|
|
321
|
+
'origin',
|
|
322
|
+
'destination',
|
|
323
|
+
'sender',
|
|
324
|
+
'agency',
|
|
325
|
+
'client',
|
|
326
|
+
'references',
|
|
327
|
+
'packages',
|
|
328
|
+
'notes',
|
|
329
|
+
]),
|
|
330
|
+
},
|
|
331
|
+
required: [
|
|
332
|
+
'shop',
|
|
333
|
+
'type',
|
|
334
|
+
'code',
|
|
335
|
+
'serviceCode',
|
|
336
|
+
'scheduleCode',
|
|
337
|
+
'date',
|
|
338
|
+
'expectedDeliveryDate',
|
|
339
|
+
'packageCount',
|
|
340
|
+
'weight',
|
|
341
|
+
'origin',
|
|
342
|
+
'destination',
|
|
343
|
+
'sender',
|
|
344
|
+
'agency',
|
|
345
|
+
'client',
|
|
346
|
+
],
|
|
347
|
+
additionalProperties: false,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const createExpeditionWithNetwork = () => ({
|
|
351
|
+
title: 'create with one or more networks',
|
|
352
|
+
type: 'object',
|
|
353
|
+
properties: {
|
|
354
|
+
...pickProperties(expedition(), ['_id', 'createdAt']),
|
|
355
|
+
network: mergeSchemas(objectWithUuid(), {
|
|
356
|
+
description: `any shop in the network can receive it, on reception \`shop\` will be set to the receiving shop`,
|
|
357
|
+
}),
|
|
358
|
+
otherNetworks: {
|
|
359
|
+
type: 'array',
|
|
360
|
+
items: objectWithUuid(),
|
|
361
|
+
minItems: 1,
|
|
362
|
+
uniqueItems: true,
|
|
363
|
+
description: `additional networks the expedition can be received in, on reception this will be removed and \`network\` and \`shop\` set to the receiving shop`,
|
|
364
|
+
},
|
|
365
|
+
...pickProperties(expedition(), [
|
|
366
|
+
'type',
|
|
367
|
+
'code',
|
|
368
|
+
'serviceCode',
|
|
369
|
+
'scheduleCode',
|
|
370
|
+
'date',
|
|
371
|
+
'expectedDeliveryDate',
|
|
372
|
+
'barcodes',
|
|
373
|
+
'packageCount',
|
|
374
|
+
'weight',
|
|
375
|
+
'volume',
|
|
376
|
+
'origin',
|
|
377
|
+
'destination',
|
|
378
|
+
'sender',
|
|
379
|
+
'agency',
|
|
380
|
+
'client',
|
|
381
|
+
'references',
|
|
382
|
+
'packages',
|
|
383
|
+
'notes',
|
|
384
|
+
]),
|
|
385
|
+
},
|
|
386
|
+
required: [
|
|
387
|
+
'network',
|
|
388
|
+
'type',
|
|
389
|
+
'code',
|
|
390
|
+
'serviceCode',
|
|
391
|
+
'scheduleCode',
|
|
392
|
+
'date',
|
|
393
|
+
'expectedDeliveryDate',
|
|
394
|
+
'packageCount',
|
|
395
|
+
'weight',
|
|
396
|
+
'origin',
|
|
397
|
+
'destination',
|
|
398
|
+
'sender',
|
|
399
|
+
'agency',
|
|
400
|
+
'client',
|
|
401
|
+
],
|
|
402
|
+
additionalProperties: false,
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
const createExpeditionRequest = () => createRequest({ oneOf: [createExpeditionWithShop(), createExpeditionWithNetwork()] });
|
|
406
|
+
|
|
407
|
+
const createExpeditionResponse = () => createResponse(expedition());
|
|
408
|
+
|
|
409
|
+
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
410
|
+
|
|
411
|
+
const findByNoShop = () => ({
|
|
412
|
+
title: 'find by no shop',
|
|
413
|
+
type: 'object',
|
|
414
|
+
properties: { shop: { type: 'null' } },
|
|
415
|
+
required: ['shop'],
|
|
416
|
+
additionalProperties: false,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
const findByStatus = () => ({
|
|
420
|
+
title: 'find by status',
|
|
421
|
+
type: 'object',
|
|
422
|
+
properties: {
|
|
423
|
+
status: {
|
|
424
|
+
type: 'object',
|
|
425
|
+
properties: { code: expedition().properties.status.properties.code },
|
|
426
|
+
required: ['code'],
|
|
427
|
+
additionalProperties: false,
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
required: ['status'],
|
|
431
|
+
additionalProperties: false,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const findByShopAndTypesAndStatus = () =>
|
|
435
|
+
mergeSchemas(findByShop(), {
|
|
436
|
+
title: 'find by shop and types and status',
|
|
437
|
+
type: 'object',
|
|
438
|
+
properties: {
|
|
439
|
+
typesAndStatus: {
|
|
440
|
+
type: 'array',
|
|
441
|
+
items: {
|
|
442
|
+
type: 'object',
|
|
443
|
+
properties: {
|
|
444
|
+
type: expedition().properties.type,
|
|
445
|
+
status: {
|
|
446
|
+
type: 'object',
|
|
447
|
+
properties: { code: expedition().properties.status.properties.code },
|
|
448
|
+
required: ['code'],
|
|
449
|
+
additionalProperties: false,
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
required: ['type', 'status'],
|
|
453
|
+
additionalProperties: false,
|
|
454
|
+
},
|
|
455
|
+
uniqueItems: true,
|
|
456
|
+
minItems: 1,
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
required: ['typesAndStatus'],
|
|
460
|
+
additionalProperties: false,
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const findByShopAndStatus = () => mergeSchemas(findByShop(), findByStatus(), { title: 'find by shop and status' });
|
|
464
|
+
|
|
465
|
+
const findByNoShopAndStatus = () => mergeSchemas(findByNoShop(), findByStatus(), { title: 'find by no shop and status' });
|
|
466
|
+
|
|
467
|
+
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
468
|
+
|
|
469
|
+
const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
|
|
470
|
+
|
|
471
|
+
const findByNetworkAndNoShop = () => mergeSchemas(findByNetwork(), findByNoShop(), { title: 'find by network and no shop' });
|
|
472
|
+
|
|
473
|
+
const findByNetworkAndNoShopAndStatus = () =>
|
|
474
|
+
mergeSchemas(findByNetworkAndNoShop(), findByStatus(), { title: 'find by network and no shop and status' });
|
|
475
|
+
|
|
476
|
+
const findByCode = () => ({
|
|
477
|
+
title: 'find by code',
|
|
478
|
+
type: 'object',
|
|
479
|
+
properties: {
|
|
480
|
+
code: expedition().properties.code,
|
|
481
|
+
},
|
|
482
|
+
required: ['code'],
|
|
483
|
+
additionalProperties: false,
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const findBySale = () => ({
|
|
487
|
+
title: 'find by sale',
|
|
488
|
+
type: 'object',
|
|
489
|
+
properties: {
|
|
490
|
+
sale: objectWithUuid(),
|
|
491
|
+
},
|
|
492
|
+
required: ['sale'],
|
|
493
|
+
additionalProperties: false,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
const findExpeditionsSuperAdminRequest = () =>
|
|
497
|
+
findRequest({
|
|
498
|
+
oneOf: [
|
|
499
|
+
findById(),
|
|
500
|
+
mergeSchemas(findByNetwork(), findByOptionalDateRange()),
|
|
501
|
+
mergeSchemas(findByNetworkAndStatus(), findByOptionalDateRange()),
|
|
502
|
+
mergeSchemas(findByNetworkAndNoShop(), findByOptionalDateRange()),
|
|
503
|
+
mergeSchemas(findByNetworkAndNoShopAndStatus(), findByOptionalDateRange()),
|
|
504
|
+
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
505
|
+
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
506
|
+
findByCode(),
|
|
507
|
+
findBySale(),
|
|
508
|
+
],
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
const findExpeditionsNetworkAdminRequest = () =>
|
|
512
|
+
findRequest({
|
|
513
|
+
oneOf: [
|
|
514
|
+
findById(),
|
|
515
|
+
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
516
|
+
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
517
|
+
mergeSchemas(findByNoShop(), findByOptionalDateRange()),
|
|
518
|
+
mergeSchemas(findByNoShopAndStatus(), findByOptionalDateRange()),
|
|
519
|
+
findByCode(),
|
|
520
|
+
findBySale(),
|
|
521
|
+
],
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
const findExpeditionsShopUserRequest = () =>
|
|
525
|
+
findRequest({
|
|
526
|
+
oneOf: [
|
|
527
|
+
findById(),
|
|
528
|
+
mergeSchemas(findByShop(), findByOptionalDateRange()),
|
|
529
|
+
mergeSchemas(findByShopAndStatus(), findByOptionalDateRange()),
|
|
530
|
+
mergeSchemas(findByShopAndTypesAndStatus(), findByOptionalDateRange()),
|
|
531
|
+
mergeSchemas(findByNoShop(), findByOptionalDateRange()),
|
|
532
|
+
mergeSchemas(findByNoShopAndStatus(), findByOptionalDateRange()),
|
|
533
|
+
findByCode(),
|
|
534
|
+
findBySale(),
|
|
535
|
+
],
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
const findExpeditionsResponse = () => findResponse(expedition());
|
|
539
|
+
|
|
540
|
+
const updateExpeditionRequest = () =>
|
|
541
|
+
updateRequest(
|
|
542
|
+
findById(),
|
|
543
|
+
{
|
|
544
|
+
type: 'object',
|
|
545
|
+
properties: {
|
|
546
|
+
...pickProperties(
|
|
547
|
+
expedition(),
|
|
548
|
+
[
|
|
549
|
+
'code',
|
|
550
|
+
'serviceCode',
|
|
551
|
+
'scheduleCode',
|
|
552
|
+
'date',
|
|
553
|
+
'expectedDeliveryDate',
|
|
554
|
+
'barcodes',
|
|
555
|
+
'packageCount',
|
|
556
|
+
'weight',
|
|
557
|
+
'origin',
|
|
558
|
+
'destination',
|
|
559
|
+
'sender',
|
|
560
|
+
'agency',
|
|
561
|
+
'client',
|
|
562
|
+
'references',
|
|
563
|
+
'packages',
|
|
564
|
+
],
|
|
565
|
+
['volume', 'notes'],
|
|
566
|
+
),
|
|
567
|
+
},
|
|
568
|
+
minProperties: 1,
|
|
569
|
+
additionalProperties: false,
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
type: 'object',
|
|
573
|
+
properties: { ...pickProperties(expedition(), ['barcodes', 'references']) },
|
|
574
|
+
minProperties: 1,
|
|
575
|
+
additionalProperties: false,
|
|
576
|
+
},
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
const updateExpeditionResponse = () => updateResponse(expedition());
|
|
580
|
+
|
|
581
|
+
const deleteExpeditionRequest = () => deleteRequest(findById());
|
|
582
|
+
|
|
583
|
+
const deleteExpeditionResponse = () => deleteResponse(expedition());
|
|
584
|
+
|
|
585
|
+
const redirectExpeditionRequest = () => ({
|
|
586
|
+
type: 'object',
|
|
587
|
+
properties: {
|
|
588
|
+
find: findById(),
|
|
589
|
+
redirect: objectWithShopId(),
|
|
590
|
+
},
|
|
591
|
+
required: ['find', 'redirect'],
|
|
592
|
+
additionalProperties: false,
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
const redirectExpeditionResponse = () => ({
|
|
596
|
+
type: 'object',
|
|
597
|
+
properties: { redirected: expedition() },
|
|
598
|
+
required: ['redirected'],
|
|
599
|
+
additionalProperties: false,
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
const objectWithTypeAndStatus = () => ({
|
|
603
|
+
type: 'object',
|
|
604
|
+
properties: {
|
|
605
|
+
type: expedition().properties.type,
|
|
606
|
+
status: {
|
|
607
|
+
type: 'object',
|
|
608
|
+
properties: { code: expedition().properties.status.properties.code },
|
|
609
|
+
required: ['code'],
|
|
610
|
+
additionalProperties: false,
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
required: ['type', 'status'],
|
|
614
|
+
additionalProperties: false,
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
const scanExpeditionRequest = () => ({
|
|
618
|
+
type: 'object',
|
|
619
|
+
properties: {
|
|
620
|
+
scan: {
|
|
621
|
+
oneOf: [
|
|
622
|
+
{
|
|
623
|
+
title: 'barcode',
|
|
624
|
+
type: 'object',
|
|
625
|
+
properties: { barcode: { type: 'string', trim: true } },
|
|
626
|
+
required: ['barcode'],
|
|
627
|
+
additionalProperties: false,
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
title: 'QR code',
|
|
631
|
+
type: 'object',
|
|
632
|
+
properties: { qrCode: { type: 'string', trim: true } },
|
|
633
|
+
required: ['qrCode'],
|
|
634
|
+
additionalProperties: false,
|
|
635
|
+
},
|
|
636
|
+
],
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
required: ['scan'],
|
|
640
|
+
additionalProperties: false,
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const resultOk = () => ({
|
|
644
|
+
title: 'ok',
|
|
645
|
+
type: 'object',
|
|
646
|
+
properties: { ok: expedition() },
|
|
647
|
+
required: ['ok'],
|
|
648
|
+
additionalProperties: false,
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
const resultNotFound = () => ({
|
|
652
|
+
title: 'not found',
|
|
653
|
+
type: 'object',
|
|
654
|
+
properties: { notFound: { type: 'boolean', enum: [true] } },
|
|
655
|
+
required: ['notFound'],
|
|
656
|
+
additionalProperties: false,
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
const resultAnotherSituation = () => ({
|
|
660
|
+
title: 'another situation',
|
|
661
|
+
type: 'object',
|
|
662
|
+
properties: { anotherSituation: objectWithTypeAndStatus() },
|
|
663
|
+
required: ['anotherSituation'],
|
|
664
|
+
additionalProperties: false,
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
const resultAnotherShop = () => ({
|
|
668
|
+
title: 'another shop',
|
|
669
|
+
type: 'object',
|
|
670
|
+
properties: {
|
|
671
|
+
anotherShop: {
|
|
672
|
+
type: 'object',
|
|
673
|
+
properties: { ...pickProperties(shop(), ['name']) },
|
|
674
|
+
required: ['name'],
|
|
675
|
+
additionalProperties: false,
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
required: ['anotherShop'],
|
|
679
|
+
additionalProperties: false,
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
const resultMultipleResults = () => ({
|
|
683
|
+
title: 'multiple results',
|
|
684
|
+
type: 'object',
|
|
685
|
+
properties: { multipleResults: { type: 'boolean', enum: [true] } },
|
|
686
|
+
required: ['multipleResults'],
|
|
687
|
+
additionalProperties: false,
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
const resultError = () => ({
|
|
691
|
+
title: 'error',
|
|
692
|
+
type: 'object',
|
|
693
|
+
properties: { error: { type: 'string' } },
|
|
694
|
+
required: ['error'],
|
|
695
|
+
additionalProperties: false,
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
const scanExpeditionResponse = () => ({
|
|
699
|
+
oneOf: [resultOk(), resultNotFound(), resultAnotherShop(), resultMultipleResults(), resultError()],
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
const processExpeditionsWithDriverRequest = () => ({
|
|
703
|
+
type: 'object',
|
|
704
|
+
properties: {
|
|
705
|
+
expeditions: omit(findByIds(), 'title'),
|
|
706
|
+
driver: driver(),
|
|
707
|
+
},
|
|
708
|
+
required: ['expeditions', 'driver'],
|
|
709
|
+
additionalProperties: false,
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
const processExpeditionsWithCustomerRequest = () => ({
|
|
713
|
+
type: 'object',
|
|
714
|
+
properties: {
|
|
715
|
+
expeditions: omit(findByIds(), 'title'),
|
|
716
|
+
customer: customerWithPod(),
|
|
717
|
+
},
|
|
718
|
+
required: ['expeditions', 'customer'],
|
|
719
|
+
additionalProperties: false,
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
const processExpeditionResultOk = () => mergeSchemas(objectWithUuid(), resultOk());
|
|
723
|
+
|
|
724
|
+
const processExpeditionResultNotFound = () => mergeSchemas(objectWithUuid(), resultNotFound());
|
|
725
|
+
|
|
726
|
+
const processExpeditionResultAnotherSituation = () => mergeSchemas(objectWithUuid(), resultAnotherSituation());
|
|
727
|
+
|
|
728
|
+
const processExpeditionResultAnotherShop = () => mergeSchemas(objectWithUuid(), resultAnotherShop());
|
|
729
|
+
|
|
730
|
+
const processExpeditionResultAnotherError = () => mergeSchemas(objectWithUuid(), resultError());
|
|
731
|
+
|
|
732
|
+
const processExpeditionsResponse = () => ({
|
|
733
|
+
type: 'object',
|
|
734
|
+
properties: {
|
|
735
|
+
expeditions: {
|
|
736
|
+
type: 'array',
|
|
737
|
+
items: {
|
|
738
|
+
oneOf: [
|
|
739
|
+
processExpeditionResultOk(),
|
|
740
|
+
processExpeditionResultNotFound(),
|
|
741
|
+
processExpeditionResultAnotherSituation(),
|
|
742
|
+
processExpeditionResultAnotherShop(),
|
|
743
|
+
processExpeditionResultAnotherError(),
|
|
744
|
+
],
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
required: ['expeditions'],
|
|
749
|
+
additionalProperties: false,
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
const receiveAllExpeditionsFromDriverRequest = () => ({
|
|
753
|
+
type: 'object',
|
|
754
|
+
properties: {
|
|
755
|
+
driver: driver(),
|
|
756
|
+
},
|
|
757
|
+
required: ['driver'],
|
|
758
|
+
additionalProperties: false,
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
const receiveAllExpeditionsFromDriverResponse = () => ({
|
|
762
|
+
type: 'object',
|
|
763
|
+
properties: {
|
|
764
|
+
expeditions: { type: 'integer', minimum: 0 },
|
|
765
|
+
},
|
|
766
|
+
required: ['expeditions'],
|
|
767
|
+
additionalProperties: false,
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
const downloadExpeditionLabelRequest = () => ({
|
|
771
|
+
type: 'object',
|
|
772
|
+
properties: {
|
|
773
|
+
download: objectWithUuid(),
|
|
774
|
+
},
|
|
775
|
+
required: ['download'],
|
|
776
|
+
additionalProperties: false,
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
const downloadExpeditionLabelResponse = () => ({
|
|
780
|
+
type: 'object',
|
|
781
|
+
properties: {
|
|
782
|
+
download: {
|
|
783
|
+
type: 'object',
|
|
784
|
+
properties: {
|
|
785
|
+
label: { type: 'string', description: 'a PDF file encoded as a Base64 string' },
|
|
786
|
+
},
|
|
787
|
+
required: ['label'],
|
|
788
|
+
additionalProperties: false,
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
required: ['download'],
|
|
792
|
+
additionalProperties: false,
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
const expireExpeditionRequest = () => ({
|
|
796
|
+
type: 'object',
|
|
797
|
+
properties: {
|
|
798
|
+
expire: objectWithUuid(),
|
|
799
|
+
},
|
|
800
|
+
required: ['expire'],
|
|
801
|
+
additionalProperties: false,
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
const unexpireExpeditionRequest = () => ({
|
|
805
|
+
type: 'object',
|
|
806
|
+
properties: {
|
|
807
|
+
unexpire: objectWithUuid(),
|
|
808
|
+
},
|
|
809
|
+
required: ['unexpire'],
|
|
810
|
+
additionalProperties: false,
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
const updateExpeditionDerivationRequest = () => ({
|
|
814
|
+
type: 'object',
|
|
815
|
+
properties: {
|
|
816
|
+
find: objectWithUuid(),
|
|
817
|
+
set: {
|
|
818
|
+
type: 'object',
|
|
819
|
+
properties: {
|
|
820
|
+
derivation: {
|
|
821
|
+
type: 'object',
|
|
822
|
+
properties: {
|
|
823
|
+
settings: derivationSettings(),
|
|
824
|
+
},
|
|
825
|
+
required: ['settings'],
|
|
826
|
+
additionalProperties: false,
|
|
827
|
+
},
|
|
828
|
+
},
|
|
829
|
+
required: ['derivation'],
|
|
830
|
+
additionalProperties: false,
|
|
831
|
+
},
|
|
832
|
+
},
|
|
833
|
+
required: ['find', 'set'],
|
|
834
|
+
additionalProperties: false,
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
module.exports = {
|
|
838
|
+
processedWithDriver,
|
|
839
|
+
processedWithCustomer,
|
|
840
|
+
processedWithCustomerWithPod,
|
|
841
|
+
expedition,
|
|
842
|
+
objectWithExpeditionId,
|
|
843
|
+
createExpeditionRequest,
|
|
844
|
+
createExpeditionResponse,
|
|
845
|
+
findExpeditionsSuperAdminRequest,
|
|
846
|
+
findExpeditionsNetworkAdminRequest,
|
|
847
|
+
findExpeditionsShopUserRequest,
|
|
848
|
+
findExpeditionsResponse,
|
|
849
|
+
updateExpeditionRequest,
|
|
850
|
+
updateExpeditionResponse,
|
|
851
|
+
deleteExpeditionRequest,
|
|
852
|
+
deleteExpeditionResponse,
|
|
853
|
+
redirectExpeditionRequest,
|
|
854
|
+
redirectExpeditionResponse,
|
|
855
|
+
scanExpeditionRequest,
|
|
856
|
+
scanExpeditionResponse,
|
|
857
|
+
processExpeditionsWithDriverRequest,
|
|
858
|
+
processExpeditionsWithCustomerRequest,
|
|
859
|
+
processExpeditionsResponse,
|
|
860
|
+
receiveAllExpeditionsFromDriverRequest,
|
|
861
|
+
receiveAllExpeditionsFromDriverResponse,
|
|
862
|
+
downloadExpeditionLabelRequest,
|
|
863
|
+
downloadExpeditionLabelResponse,
|
|
864
|
+
expireExpeditionRequest,
|
|
865
|
+
unexpireExpeditionRequest,
|
|
866
|
+
updateExpeditionDerivationRequest,
|
|
867
|
+
};
|