@gls_spain/gps-common 34.9.2 → 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 -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 +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 -699
|
@@ -1,404 +1,404 @@
|
|
|
1
|
-
const {
|
|
2
|
-
uuid,
|
|
3
|
-
objectWithUuid,
|
|
4
|
-
datetime,
|
|
5
|
-
timeRange,
|
|
6
|
-
createRequest,
|
|
7
|
-
createResponse,
|
|
8
|
-
findRequest,
|
|
9
|
-
findResponse,
|
|
10
|
-
updateRequest,
|
|
11
|
-
updateResponse,
|
|
12
|
-
deleteRequest,
|
|
13
|
-
deleteResponse,
|
|
14
|
-
schemaOrNull,
|
|
15
|
-
mergeSchemas,
|
|
16
|
-
pickProperties,
|
|
17
|
-
} = require('@gls_spain/common-json-schemas');
|
|
18
|
-
const {
|
|
19
|
-
addressWithRequiredLocation,
|
|
20
|
-
findAll,
|
|
21
|
-
findById,
|
|
22
|
-
findByName,
|
|
23
|
-
findByAddress,
|
|
24
|
-
findByCircularArea,
|
|
25
|
-
findByPolygonalArea,
|
|
26
|
-
timezone,
|
|
27
|
-
contact,
|
|
28
|
-
fiscal,
|
|
29
|
-
findByFiscal,
|
|
30
|
-
} = require('./common');
|
|
31
|
-
const { network, objectWithNetworkId } = require('./networks');
|
|
32
|
-
const { defaults, derivationSettings, expirationSettings } = require('./defaults');
|
|
33
|
-
const { zone } = require('./zones');
|
|
34
|
-
const { representative } = require('./representatives');
|
|
35
|
-
|
|
36
|
-
const shopDaySchedule = () => ({
|
|
37
|
-
title: 'array of time ranges',
|
|
38
|
-
type: 'array',
|
|
39
|
-
items: timeRange(),
|
|
40
|
-
minItems: 0,
|
|
41
|
-
maxItems: 2,
|
|
42
|
-
additionalProperties: false,
|
|
43
|
-
description: '[ ] or [ [HH:mm:ss, HH:mm:ss] ] or [ [HH:mm:ss, HH:mm:ss], [HH:mm:ss, HH:mm:ss] ]',
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const shopSchedule = () => ({
|
|
47
|
-
oneOf: [
|
|
48
|
-
{
|
|
49
|
-
title: 'weekly schedule',
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
type: { type: 'string', enum: ['weekly'] },
|
|
53
|
-
weekly: shopDaySchedule(),
|
|
54
|
-
saturday: shopDaySchedule(),
|
|
55
|
-
},
|
|
56
|
-
required: ['type', 'weekly', 'saturday'],
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
title: 'daily schedule',
|
|
61
|
-
type: 'object',
|
|
62
|
-
properties: {
|
|
63
|
-
type: { type: 'string', enum: ['daily'] },
|
|
64
|
-
monday: shopDaySchedule(),
|
|
65
|
-
tuesday: shopDaySchedule(),
|
|
66
|
-
wednesday: shopDaySchedule(),
|
|
67
|
-
thursday: shopDaySchedule(),
|
|
68
|
-
friday: shopDaySchedule(),
|
|
69
|
-
saturday: shopDaySchedule(),
|
|
70
|
-
},
|
|
71
|
-
required: ['type', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
|
|
72
|
-
additionalProperties: false,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const shopRepresentative = () => ({
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: {
|
|
80
|
-
...pickProperties(representative(), ['_id', 'name']),
|
|
81
|
-
since: datetime(),
|
|
82
|
-
},
|
|
83
|
-
required: ['_id', 'name', 'since'],
|
|
84
|
-
additionalProperties: false,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const shopActivity = () => ({
|
|
88
|
-
type: 'string',
|
|
89
|
-
enum: [
|
|
90
|
-
'bookshop',
|
|
91
|
-
'press',
|
|
92
|
-
'bazaar',
|
|
93
|
-
'telecom',
|
|
94
|
-
'mobileAccessories',
|
|
95
|
-
'inkSupplies',
|
|
96
|
-
'computer',
|
|
97
|
-
'optics',
|
|
98
|
-
'pharmacy',
|
|
99
|
-
'food',
|
|
100
|
-
'hardware',
|
|
101
|
-
'tobacco',
|
|
102
|
-
'lottery',
|
|
103
|
-
'clothing',
|
|
104
|
-
'barberShop',
|
|
105
|
-
'bar',
|
|
106
|
-
'appliances',
|
|
107
|
-
'repairShop',
|
|
108
|
-
'gasStation',
|
|
109
|
-
'realState',
|
|
110
|
-
'travelAgency',
|
|
111
|
-
'legal',
|
|
112
|
-
'academy',
|
|
113
|
-
'sportsShop',
|
|
114
|
-
'gardenAndPets',
|
|
115
|
-
'photos',
|
|
116
|
-
'jewelryStore',
|
|
117
|
-
'shoeShop',
|
|
118
|
-
'other',
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const shop = () => ({
|
|
123
|
-
title: 'shop',
|
|
124
|
-
type: 'object',
|
|
125
|
-
properties: {
|
|
126
|
-
_id: uuid(),
|
|
127
|
-
createdAt: datetime(),
|
|
128
|
-
updatedAt: datetime(),
|
|
129
|
-
deletable: { type: 'boolean' },
|
|
130
|
-
readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
|
|
131
|
-
international: {
|
|
132
|
-
type: 'object',
|
|
133
|
-
properties: {
|
|
134
|
-
partnerKey: { type: 'string' },
|
|
135
|
-
parcelShopId: { type: 'string' },
|
|
136
|
-
},
|
|
137
|
-
required: ['partnerKey', 'parcelShopId'],
|
|
138
|
-
additionalProperties: false,
|
|
139
|
-
},
|
|
140
|
-
defaults: {
|
|
141
|
-
type: 'object',
|
|
142
|
-
properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
|
|
143
|
-
required: ['derivationSettings', 'expirationSettings'],
|
|
144
|
-
additionalProperties: false,
|
|
145
|
-
},
|
|
146
|
-
network: {
|
|
147
|
-
type: 'object',
|
|
148
|
-
properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
|
|
149
|
-
required: ['_id', 'name'],
|
|
150
|
-
additionalProperties: false,
|
|
151
|
-
},
|
|
152
|
-
zone: {
|
|
153
|
-
type: 'object',
|
|
154
|
-
properties: { ...pickProperties(zone(), ['_id', 'name']) },
|
|
155
|
-
required: ['_id', 'name'],
|
|
156
|
-
additionalProperties: false,
|
|
157
|
-
},
|
|
158
|
-
openingRepresentative: shopRepresentative(),
|
|
159
|
-
managingRepresentative: shopRepresentative(),
|
|
160
|
-
status: {
|
|
161
|
-
type: 'object',
|
|
162
|
-
properties: {
|
|
163
|
-
code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
|
|
164
|
-
disabled: {
|
|
165
|
-
type: 'object',
|
|
166
|
-
properties: {
|
|
167
|
-
at: datetime(),
|
|
168
|
-
reason: { type: 'string', trim: true },
|
|
169
|
-
},
|
|
170
|
-
required: ['at', 'reason'],
|
|
171
|
-
additionalProperties: false,
|
|
172
|
-
},
|
|
173
|
-
manuallyDisabled: {
|
|
174
|
-
type: 'object',
|
|
175
|
-
properties: {
|
|
176
|
-
at: datetime(),
|
|
177
|
-
reason: { type: 'string', trim: true },
|
|
178
|
-
},
|
|
179
|
-
required: ['at', 'reason'],
|
|
180
|
-
additionalProperties: false,
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
required: ['code'],
|
|
184
|
-
additionalProperties: false,
|
|
185
|
-
},
|
|
186
|
-
name: { type: 'string', trim: true },
|
|
187
|
-
address: addressWithRequiredLocation(),
|
|
188
|
-
capabilities: {
|
|
189
|
-
type: 'array',
|
|
190
|
-
items: { type: 'string', enum: ['deliver', 'pickup', 'sell'] },
|
|
191
|
-
uniqueItems: true,
|
|
192
|
-
},
|
|
193
|
-
openingSchedule: shopSchedule(),
|
|
194
|
-
timezone: timezone(),
|
|
195
|
-
contacts: {
|
|
196
|
-
type: 'array',
|
|
197
|
-
items: contact(),
|
|
198
|
-
},
|
|
199
|
-
fiscal: fiscal(),
|
|
200
|
-
activity: shopActivity(),
|
|
201
|
-
notes: { type: 'string', trim: true },
|
|
202
|
-
derivationSettings: derivationSettings(),
|
|
203
|
-
expirationSettings: expirationSettings(),
|
|
204
|
-
},
|
|
205
|
-
required: [
|
|
206
|
-
'_id',
|
|
207
|
-
'createdAt',
|
|
208
|
-
'updatedAt',
|
|
209
|
-
'deletable',
|
|
210
|
-
'readonly',
|
|
211
|
-
'international',
|
|
212
|
-
'defaults',
|
|
213
|
-
'network',
|
|
214
|
-
'status',
|
|
215
|
-
'name',
|
|
216
|
-
'address',
|
|
217
|
-
'capabilities',
|
|
218
|
-
'openingSchedule',
|
|
219
|
-
'timezone',
|
|
220
|
-
'contacts',
|
|
221
|
-
],
|
|
222
|
-
additionalProperties: false,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const objectWithShopId = () => ({
|
|
226
|
-
type: 'object',
|
|
227
|
-
properties: { shop: objectWithUuid() },
|
|
228
|
-
required: ['shop'],
|
|
229
|
-
additionalProperties: false,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const setShopStatus = () => ({
|
|
233
|
-
type: 'object',
|
|
234
|
-
properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
|
|
235
|
-
additionalProperties: false,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const setShopRepresentative = () => ({
|
|
239
|
-
type: 'object',
|
|
240
|
-
properties: {
|
|
241
|
-
...pickProperties(representative(), ['_id']),
|
|
242
|
-
since: datetime(),
|
|
243
|
-
},
|
|
244
|
-
required: ['_id', 'since'],
|
|
245
|
-
additionalProperties: false,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
const createShopRequest = () =>
|
|
249
|
-
createRequest({
|
|
250
|
-
type: 'object',
|
|
251
|
-
properties: {
|
|
252
|
-
...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
|
|
253
|
-
network: objectWithUuid(),
|
|
254
|
-
zone: objectWithUuid(),
|
|
255
|
-
openingRepresentative: setShopRepresentative(),
|
|
256
|
-
managingRepresentative: setShopRepresentative(),
|
|
257
|
-
status: setShopStatus(),
|
|
258
|
-
...pickProperties(shop(), [
|
|
259
|
-
'name',
|
|
260
|
-
'address',
|
|
261
|
-
'capabilities',
|
|
262
|
-
'openingSchedule',
|
|
263
|
-
'timezone',
|
|
264
|
-
'contacts',
|
|
265
|
-
'fiscal',
|
|
266
|
-
'activity',
|
|
267
|
-
'notes',
|
|
268
|
-
'derivationSettings',
|
|
269
|
-
'expirationSettings',
|
|
270
|
-
]),
|
|
271
|
-
},
|
|
272
|
-
required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
|
|
273
|
-
additionalProperties: false,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
const createShopResponse = () => createResponse(shop());
|
|
277
|
-
|
|
278
|
-
const findByStatus = () => ({
|
|
279
|
-
title: 'find by status',
|
|
280
|
-
type: 'object',
|
|
281
|
-
properties: {
|
|
282
|
-
status: {
|
|
283
|
-
type: 'object',
|
|
284
|
-
properties: { ...pickProperties(shop().properties.status, ['code']) },
|
|
285
|
-
required: ['code'],
|
|
286
|
-
additionalProperties: false,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
required: ['status'],
|
|
290
|
-
additionalProperties: false,
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
|
|
294
|
-
|
|
295
|
-
const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
|
|
296
|
-
|
|
297
|
-
const findByStatusAndPolygonalArea = () =>
|
|
298
|
-
mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
|
|
299
|
-
|
|
300
|
-
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
301
|
-
|
|
302
|
-
const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
|
|
303
|
-
|
|
304
|
-
const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
|
|
305
|
-
|
|
306
|
-
const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
|
|
307
|
-
|
|
308
|
-
const findByNetworkAndStatusAndName = () =>
|
|
309
|
-
mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
|
|
310
|
-
|
|
311
|
-
const findByNetworkAndStatusAndCircularArea = () =>
|
|
312
|
-
mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
|
|
313
|
-
|
|
314
|
-
const findByNetworkAndStatusAndPolygonalArea = () =>
|
|
315
|
-
mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
|
|
316
|
-
|
|
317
|
-
const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
|
|
318
|
-
|
|
319
|
-
const findShopsSuperAdminRequest = () =>
|
|
320
|
-
findRequest({
|
|
321
|
-
oneOf: [
|
|
322
|
-
findAll(),
|
|
323
|
-
findById(),
|
|
324
|
-
findByStatus(),
|
|
325
|
-
findByName(),
|
|
326
|
-
findByAddress(),
|
|
327
|
-
findByStatusAndName(),
|
|
328
|
-
findByStatusAndCircularArea(),
|
|
329
|
-
findByStatusAndPolygonalArea(),
|
|
330
|
-
findByFiscal(),
|
|
331
|
-
findByNetwork(),
|
|
332
|
-
findByNetworkAndStatus(),
|
|
333
|
-
findByNetworkAndName(),
|
|
334
|
-
findByNetworkAndAddress(),
|
|
335
|
-
findByNetworkAndStatusAndName(),
|
|
336
|
-
findByNetworkAndStatusAndCircularArea(),
|
|
337
|
-
findByNetworkAndStatusAndPolygonalArea(),
|
|
338
|
-
findByNetworkAndFiscal(),
|
|
339
|
-
],
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
const findShopsNetworkAdminRequest = () =>
|
|
343
|
-
findRequest({
|
|
344
|
-
oneOf: [
|
|
345
|
-
findAll(),
|
|
346
|
-
findById(),
|
|
347
|
-
findByStatus(),
|
|
348
|
-
findByName(),
|
|
349
|
-
findByAddress(),
|
|
350
|
-
findByStatusAndName(),
|
|
351
|
-
findByStatusAndCircularArea(),
|
|
352
|
-
findByStatusAndPolygonalArea(),
|
|
353
|
-
findByFiscal(),
|
|
354
|
-
],
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
const findShopsResponse = () => findResponse(shop());
|
|
358
|
-
|
|
359
|
-
const updateShopRequest = () =>
|
|
360
|
-
updateRequest(
|
|
361
|
-
findById(),
|
|
362
|
-
{
|
|
363
|
-
type: 'object',
|
|
364
|
-
properties: {
|
|
365
|
-
zone: schemaOrNull(objectWithUuid()),
|
|
366
|
-
openingRepresentative: schemaOrNull(setShopRepresentative()),
|
|
367
|
-
managingRepresentative: schemaOrNull(setShopRepresentative()),
|
|
368
|
-
status: setShopStatus(),
|
|
369
|
-
...pickProperties(
|
|
370
|
-
shop(),
|
|
371
|
-
['name', 'address', 'capabilities', 'openingSchedule', 'contacts'],
|
|
372
|
-
['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
|
|
373
|
-
),
|
|
374
|
-
},
|
|
375
|
-
minProperties: 1,
|
|
376
|
-
additionalProperties: false,
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
type: 'object',
|
|
380
|
-
properties: { ...pickProperties(shop(), ['capabilities']) },
|
|
381
|
-
minProperties: 1,
|
|
382
|
-
additionalProperties: false,
|
|
383
|
-
},
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
const updateShopResponse = () => updateResponse(shop());
|
|
387
|
-
|
|
388
|
-
const deleteShopRequest = () => deleteRequest(findById());
|
|
389
|
-
|
|
390
|
-
const deleteShopResponse = () => deleteResponse(shop());
|
|
391
|
-
|
|
392
|
-
module.exports = {
|
|
393
|
-
shop,
|
|
394
|
-
objectWithShopId,
|
|
395
|
-
createShopRequest,
|
|
396
|
-
createShopResponse,
|
|
397
|
-
findShopsSuperAdminRequest,
|
|
398
|
-
findShopsNetworkAdminRequest,
|
|
399
|
-
findShopsResponse,
|
|
400
|
-
updateShopRequest,
|
|
401
|
-
updateShopResponse,
|
|
402
|
-
deleteShopRequest,
|
|
403
|
-
deleteShopResponse,
|
|
404
|
-
};
|
|
1
|
+
const {
|
|
2
|
+
uuid,
|
|
3
|
+
objectWithUuid,
|
|
4
|
+
datetime,
|
|
5
|
+
timeRange,
|
|
6
|
+
createRequest,
|
|
7
|
+
createResponse,
|
|
8
|
+
findRequest,
|
|
9
|
+
findResponse,
|
|
10
|
+
updateRequest,
|
|
11
|
+
updateResponse,
|
|
12
|
+
deleteRequest,
|
|
13
|
+
deleteResponse,
|
|
14
|
+
schemaOrNull,
|
|
15
|
+
mergeSchemas,
|
|
16
|
+
pickProperties,
|
|
17
|
+
} = require('@gls_spain/common-json-schemas');
|
|
18
|
+
const {
|
|
19
|
+
addressWithRequiredLocation,
|
|
20
|
+
findAll,
|
|
21
|
+
findById,
|
|
22
|
+
findByName,
|
|
23
|
+
findByAddress,
|
|
24
|
+
findByCircularArea,
|
|
25
|
+
findByPolygonalArea,
|
|
26
|
+
timezone,
|
|
27
|
+
contact,
|
|
28
|
+
fiscal,
|
|
29
|
+
findByFiscal,
|
|
30
|
+
} = require('./common');
|
|
31
|
+
const { network, objectWithNetworkId } = require('./networks');
|
|
32
|
+
const { defaults, derivationSettings, expirationSettings } = require('./defaults');
|
|
33
|
+
const { zone } = require('./zones');
|
|
34
|
+
const { representative } = require('./representatives');
|
|
35
|
+
|
|
36
|
+
const shopDaySchedule = () => ({
|
|
37
|
+
title: 'array of time ranges',
|
|
38
|
+
type: 'array',
|
|
39
|
+
items: timeRange(),
|
|
40
|
+
minItems: 0,
|
|
41
|
+
maxItems: 2,
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
description: '[ ] or [ [HH:mm:ss, HH:mm:ss] ] or [ [HH:mm:ss, HH:mm:ss], [HH:mm:ss, HH:mm:ss] ]',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const shopSchedule = () => ({
|
|
47
|
+
oneOf: [
|
|
48
|
+
{
|
|
49
|
+
title: 'weekly schedule',
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
type: { type: 'string', enum: ['weekly'] },
|
|
53
|
+
weekly: shopDaySchedule(),
|
|
54
|
+
saturday: shopDaySchedule(),
|
|
55
|
+
},
|
|
56
|
+
required: ['type', 'weekly', 'saturday'],
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
title: 'daily schedule',
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
type: { type: 'string', enum: ['daily'] },
|
|
64
|
+
monday: shopDaySchedule(),
|
|
65
|
+
tuesday: shopDaySchedule(),
|
|
66
|
+
wednesday: shopDaySchedule(),
|
|
67
|
+
thursday: shopDaySchedule(),
|
|
68
|
+
friday: shopDaySchedule(),
|
|
69
|
+
saturday: shopDaySchedule(),
|
|
70
|
+
},
|
|
71
|
+
required: ['type', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const shopRepresentative = () => ({
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
...pickProperties(representative(), ['_id', 'name']),
|
|
81
|
+
since: datetime(),
|
|
82
|
+
},
|
|
83
|
+
required: ['_id', 'name', 'since'],
|
|
84
|
+
additionalProperties: false,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const shopActivity = () => ({
|
|
88
|
+
type: 'string',
|
|
89
|
+
enum: [
|
|
90
|
+
'bookshop',
|
|
91
|
+
'press',
|
|
92
|
+
'bazaar',
|
|
93
|
+
'telecom',
|
|
94
|
+
'mobileAccessories',
|
|
95
|
+
'inkSupplies',
|
|
96
|
+
'computer',
|
|
97
|
+
'optics',
|
|
98
|
+
'pharmacy',
|
|
99
|
+
'food',
|
|
100
|
+
'hardware',
|
|
101
|
+
'tobacco',
|
|
102
|
+
'lottery',
|
|
103
|
+
'clothing',
|
|
104
|
+
'barberShop',
|
|
105
|
+
'bar',
|
|
106
|
+
'appliances',
|
|
107
|
+
'repairShop',
|
|
108
|
+
'gasStation',
|
|
109
|
+
'realState',
|
|
110
|
+
'travelAgency',
|
|
111
|
+
'legal',
|
|
112
|
+
'academy',
|
|
113
|
+
'sportsShop',
|
|
114
|
+
'gardenAndPets',
|
|
115
|
+
'photos',
|
|
116
|
+
'jewelryStore',
|
|
117
|
+
'shoeShop',
|
|
118
|
+
'other',
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const shop = () => ({
|
|
123
|
+
title: 'shop',
|
|
124
|
+
type: 'object',
|
|
125
|
+
properties: {
|
|
126
|
+
_id: uuid(),
|
|
127
|
+
createdAt: datetime(),
|
|
128
|
+
updatedAt: datetime(),
|
|
129
|
+
deletable: { type: 'boolean' },
|
|
130
|
+
readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
|
|
131
|
+
international: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
properties: {
|
|
134
|
+
partnerKey: { type: 'string' },
|
|
135
|
+
parcelShopId: { type: 'string' },
|
|
136
|
+
},
|
|
137
|
+
required: ['partnerKey', 'parcelShopId'],
|
|
138
|
+
additionalProperties: false,
|
|
139
|
+
},
|
|
140
|
+
defaults: {
|
|
141
|
+
type: 'object',
|
|
142
|
+
properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
|
|
143
|
+
required: ['derivationSettings', 'expirationSettings'],
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
},
|
|
146
|
+
network: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
|
|
149
|
+
required: ['_id', 'name'],
|
|
150
|
+
additionalProperties: false,
|
|
151
|
+
},
|
|
152
|
+
zone: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: { ...pickProperties(zone(), ['_id', 'name']) },
|
|
155
|
+
required: ['_id', 'name'],
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
},
|
|
158
|
+
openingRepresentative: shopRepresentative(),
|
|
159
|
+
managingRepresentative: shopRepresentative(),
|
|
160
|
+
status: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
|
|
164
|
+
disabled: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
at: datetime(),
|
|
168
|
+
reason: { type: 'string', trim: true },
|
|
169
|
+
},
|
|
170
|
+
required: ['at', 'reason'],
|
|
171
|
+
additionalProperties: false,
|
|
172
|
+
},
|
|
173
|
+
manuallyDisabled: {
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
at: datetime(),
|
|
177
|
+
reason: { type: 'string', trim: true },
|
|
178
|
+
},
|
|
179
|
+
required: ['at', 'reason'],
|
|
180
|
+
additionalProperties: false,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
required: ['code'],
|
|
184
|
+
additionalProperties: false,
|
|
185
|
+
},
|
|
186
|
+
name: { type: 'string', trim: true },
|
|
187
|
+
address: addressWithRequiredLocation(),
|
|
188
|
+
capabilities: {
|
|
189
|
+
type: 'array',
|
|
190
|
+
items: { type: 'string', enum: ['deliver', 'pickup', 'sell'] },
|
|
191
|
+
uniqueItems: true,
|
|
192
|
+
},
|
|
193
|
+
openingSchedule: shopSchedule(),
|
|
194
|
+
timezone: timezone(),
|
|
195
|
+
contacts: {
|
|
196
|
+
type: 'array',
|
|
197
|
+
items: contact(),
|
|
198
|
+
},
|
|
199
|
+
fiscal: fiscal(),
|
|
200
|
+
activity: shopActivity(),
|
|
201
|
+
notes: { type: 'string', trim: true },
|
|
202
|
+
derivationSettings: derivationSettings(),
|
|
203
|
+
expirationSettings: expirationSettings(),
|
|
204
|
+
},
|
|
205
|
+
required: [
|
|
206
|
+
'_id',
|
|
207
|
+
'createdAt',
|
|
208
|
+
'updatedAt',
|
|
209
|
+
'deletable',
|
|
210
|
+
'readonly',
|
|
211
|
+
'international',
|
|
212
|
+
'defaults',
|
|
213
|
+
'network',
|
|
214
|
+
'status',
|
|
215
|
+
'name',
|
|
216
|
+
'address',
|
|
217
|
+
'capabilities',
|
|
218
|
+
'openingSchedule',
|
|
219
|
+
'timezone',
|
|
220
|
+
'contacts',
|
|
221
|
+
],
|
|
222
|
+
additionalProperties: false,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const objectWithShopId = () => ({
|
|
226
|
+
type: 'object',
|
|
227
|
+
properties: { shop: objectWithUuid() },
|
|
228
|
+
required: ['shop'],
|
|
229
|
+
additionalProperties: false,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const setShopStatus = () => ({
|
|
233
|
+
type: 'object',
|
|
234
|
+
properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
|
|
235
|
+
additionalProperties: false,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const setShopRepresentative = () => ({
|
|
239
|
+
type: 'object',
|
|
240
|
+
properties: {
|
|
241
|
+
...pickProperties(representative(), ['_id']),
|
|
242
|
+
since: datetime(),
|
|
243
|
+
},
|
|
244
|
+
required: ['_id', 'since'],
|
|
245
|
+
additionalProperties: false,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const createShopRequest = () =>
|
|
249
|
+
createRequest({
|
|
250
|
+
type: 'object',
|
|
251
|
+
properties: {
|
|
252
|
+
...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
|
|
253
|
+
network: objectWithUuid(),
|
|
254
|
+
zone: objectWithUuid(),
|
|
255
|
+
openingRepresentative: setShopRepresentative(),
|
|
256
|
+
managingRepresentative: setShopRepresentative(),
|
|
257
|
+
status: setShopStatus(),
|
|
258
|
+
...pickProperties(shop(), [
|
|
259
|
+
'name',
|
|
260
|
+
'address',
|
|
261
|
+
'capabilities',
|
|
262
|
+
'openingSchedule',
|
|
263
|
+
'timezone',
|
|
264
|
+
'contacts',
|
|
265
|
+
'fiscal',
|
|
266
|
+
'activity',
|
|
267
|
+
'notes',
|
|
268
|
+
'derivationSettings',
|
|
269
|
+
'expirationSettings',
|
|
270
|
+
]),
|
|
271
|
+
},
|
|
272
|
+
required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
|
|
273
|
+
additionalProperties: false,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const createShopResponse = () => createResponse(shop());
|
|
277
|
+
|
|
278
|
+
const findByStatus = () => ({
|
|
279
|
+
title: 'find by status',
|
|
280
|
+
type: 'object',
|
|
281
|
+
properties: {
|
|
282
|
+
status: {
|
|
283
|
+
type: 'object',
|
|
284
|
+
properties: { ...pickProperties(shop().properties.status, ['code']) },
|
|
285
|
+
required: ['code'],
|
|
286
|
+
additionalProperties: false,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
required: ['status'],
|
|
290
|
+
additionalProperties: false,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
|
|
294
|
+
|
|
295
|
+
const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
|
|
296
|
+
|
|
297
|
+
const findByStatusAndPolygonalArea = () =>
|
|
298
|
+
mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
|
|
299
|
+
|
|
300
|
+
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
301
|
+
|
|
302
|
+
const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
|
|
303
|
+
|
|
304
|
+
const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
|
|
305
|
+
|
|
306
|
+
const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
|
|
307
|
+
|
|
308
|
+
const findByNetworkAndStatusAndName = () =>
|
|
309
|
+
mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
|
|
310
|
+
|
|
311
|
+
const findByNetworkAndStatusAndCircularArea = () =>
|
|
312
|
+
mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
|
|
313
|
+
|
|
314
|
+
const findByNetworkAndStatusAndPolygonalArea = () =>
|
|
315
|
+
mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
|
|
316
|
+
|
|
317
|
+
const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
|
|
318
|
+
|
|
319
|
+
const findShopsSuperAdminRequest = () =>
|
|
320
|
+
findRequest({
|
|
321
|
+
oneOf: [
|
|
322
|
+
findAll(),
|
|
323
|
+
findById(),
|
|
324
|
+
findByStatus(),
|
|
325
|
+
findByName(),
|
|
326
|
+
findByAddress(),
|
|
327
|
+
findByStatusAndName(),
|
|
328
|
+
findByStatusAndCircularArea(),
|
|
329
|
+
findByStatusAndPolygonalArea(),
|
|
330
|
+
findByFiscal(),
|
|
331
|
+
findByNetwork(),
|
|
332
|
+
findByNetworkAndStatus(),
|
|
333
|
+
findByNetworkAndName(),
|
|
334
|
+
findByNetworkAndAddress(),
|
|
335
|
+
findByNetworkAndStatusAndName(),
|
|
336
|
+
findByNetworkAndStatusAndCircularArea(),
|
|
337
|
+
findByNetworkAndStatusAndPolygonalArea(),
|
|
338
|
+
findByNetworkAndFiscal(),
|
|
339
|
+
],
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const findShopsNetworkAdminRequest = () =>
|
|
343
|
+
findRequest({
|
|
344
|
+
oneOf: [
|
|
345
|
+
findAll(),
|
|
346
|
+
findById(),
|
|
347
|
+
findByStatus(),
|
|
348
|
+
findByName(),
|
|
349
|
+
findByAddress(),
|
|
350
|
+
findByStatusAndName(),
|
|
351
|
+
findByStatusAndCircularArea(),
|
|
352
|
+
findByStatusAndPolygonalArea(),
|
|
353
|
+
findByFiscal(),
|
|
354
|
+
],
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const findShopsResponse = () => findResponse(shop());
|
|
358
|
+
|
|
359
|
+
const updateShopRequest = () =>
|
|
360
|
+
updateRequest(
|
|
361
|
+
findById(),
|
|
362
|
+
{
|
|
363
|
+
type: 'object',
|
|
364
|
+
properties: {
|
|
365
|
+
zone: schemaOrNull(objectWithUuid()),
|
|
366
|
+
openingRepresentative: schemaOrNull(setShopRepresentative()),
|
|
367
|
+
managingRepresentative: schemaOrNull(setShopRepresentative()),
|
|
368
|
+
status: setShopStatus(),
|
|
369
|
+
...pickProperties(
|
|
370
|
+
shop(),
|
|
371
|
+
['name', 'address', 'capabilities', 'openingSchedule', 'contacts'],
|
|
372
|
+
['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
|
|
373
|
+
),
|
|
374
|
+
},
|
|
375
|
+
minProperties: 1,
|
|
376
|
+
additionalProperties: false,
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
type: 'object',
|
|
380
|
+
properties: { ...pickProperties(shop(), ['capabilities']) },
|
|
381
|
+
minProperties: 1,
|
|
382
|
+
additionalProperties: false,
|
|
383
|
+
},
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
const updateShopResponse = () => updateResponse(shop());
|
|
387
|
+
|
|
388
|
+
const deleteShopRequest = () => deleteRequest(findById());
|
|
389
|
+
|
|
390
|
+
const deleteShopResponse = () => deleteResponse(shop());
|
|
391
|
+
|
|
392
|
+
module.exports = {
|
|
393
|
+
shop,
|
|
394
|
+
objectWithShopId,
|
|
395
|
+
createShopRequest,
|
|
396
|
+
createShopResponse,
|
|
397
|
+
findShopsSuperAdminRequest,
|
|
398
|
+
findShopsNetworkAdminRequest,
|
|
399
|
+
findShopsResponse,
|
|
400
|
+
updateShopRequest,
|
|
401
|
+
updateShopResponse,
|
|
402
|
+
deleteShopRequest,
|
|
403
|
+
deleteShopResponse,
|
|
404
|
+
};
|