@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.
Files changed (81) hide show
  1. package/.eslintignore +1 -1
  2. package/.eslintrc.json +11 -11
  3. package/.idea/codeStyles/Project.xml +36 -36
  4. package/.idea/codeStyles/codeStyleConfig.xml +4 -4
  5. package/.idea/gps-common.iml +11 -11
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -6
  7. package/.idea/jsLibraryMappings.xml +5 -5
  8. package/.idea/misc.xml +5 -5
  9. package/.idea/modules.xml +7 -7
  10. package/.idea/prettier.xml +6 -6
  11. package/.idea/scopes/Source_files.xml +2 -2
  12. package/.idea/vcs.xml +5 -5
  13. package/.prettierignore +4 -4
  14. package/.prettierrc.json +13 -13
  15. package/.releaserc +17 -17
  16. package/CHANGELOG.md +1271 -1257
  17. package/README.md +103 -103
  18. package/errors/CountersDoNotExistError.js +11 -11
  19. package/errors/DatabaseNotEmptyError.js +11 -11
  20. package/errors/DefaultsDoNotExistError.js +11 -11
  21. package/errors/ExpeditionAlreadyExistsError.js +11 -11
  22. package/errors/ExpeditionCannotBeDeletedError.js +11 -11
  23. package/errors/ExpeditionCannotBeUpdatedError.js +11 -11
  24. package/errors/ExpeditionDoesNotExistError.js +11 -11
  25. package/errors/GLSRecordingError.js +11 -11
  26. package/errors/GLSSpainError.js +11 -11
  27. package/errors/InconsistentSalesSettingsError.js +11 -11
  28. package/errors/InvalidSaleDestinationError.js +11 -11
  29. package/errors/LabelDoesNotExistError.js +11 -11
  30. package/errors/NetworkAlreadyExistsError.js +11 -11
  31. package/errors/NetworkCannotBeDeletedError.js +11 -11
  32. package/errors/NetworkCannotBeUpdatedError.js +11 -11
  33. package/errors/NetworkDoesNotExistError.js +11 -11
  34. package/errors/RepresentativeAlreadyExistsError.js +11 -11
  35. package/errors/RepresentativeCannotBeDeletedError.js +11 -11
  36. package/errors/RepresentativeDoesNotExistError.js +11 -11
  37. package/errors/SaleAlreadyExistsError.js +11 -11
  38. package/errors/SaleDoesNotExistError.js +11 -11
  39. package/errors/ShopAlreadyExistsError.js +11 -11
  40. package/errors/ShopCannotBeDeletedError.js +11 -11
  41. package/errors/ShopCannotBeUpdatedError.js +11 -11
  42. package/errors/ShopCannotSellError.js +11 -11
  43. package/errors/ShopDoesNotExistError.js +11 -11
  44. package/errors/ShopNotEnabledError.js +11 -11
  45. package/errors/UserAlreadyExistsError.js +11 -11
  46. package/errors/UserCannotBeDeletedError.js +11 -11
  47. package/errors/UserCannotBeUpdatedError.js +11 -11
  48. package/errors/UserDoesNotExistError.js +11 -11
  49. package/errors/WrongNetworkError.js +11 -11
  50. package/errors/WrongPasswordError.js +11 -11
  51. package/errors/WrongShopError.js +11 -11
  52. package/errors/ZoneAlreadyExistsError.js +11 -11
  53. package/errors/ZoneCannotBeDeletedError.js +11 -11
  54. package/errors/ZoneDoesNotExistError.js +11 -11
  55. package/errors/index.js +118 -118
  56. package/index.js +9 -9
  57. package/index.test.js +36 -36
  58. package/jest.config.js +5 -5
  59. package/open-api-spec/index.js +3715 -3715
  60. package/package.json +65 -69
  61. package/schemas/definitions/become.js +5 -5
  62. package/schemas/definitions/common.js +462 -451
  63. package/schemas/definitions/counters.js +43 -43
  64. package/schemas/definitions/defaults.js +140 -140
  65. package/schemas/definitions/expeditions.js +867 -867
  66. package/schemas/definitions/gls-spain-integration-events.js +139 -139
  67. package/schemas/definitions/historic-records.js +90 -90
  68. package/schemas/definitions/integrations.js +38 -38
  69. package/schemas/definitions/login.js +38 -38
  70. package/schemas/definitions/logout.js +8 -8
  71. package/schemas/definitions/networks.js +123 -123
  72. package/schemas/definitions/pods.js +26 -26
  73. package/schemas/definitions/representatives.js +194 -194
  74. package/schemas/definitions/sales.js +253 -249
  75. package/schemas/definitions/shops.js +413 -404
  76. package/schemas/definitions/users.js +337 -337
  77. package/schemas/definitions/zones.js +92 -92
  78. package/schemas/index.js +400 -400
  79. package/scripts/build-documentation.js +40 -40
  80. package/scripts/build-json-schemas.js +35 -35
  81. package/.idea/workspace.xml +0 -699
@@ -1,404 +1,413 @@
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
+ 'herbalist',
100
+ 'food',
101
+ 'hardware',
102
+ 'tobacco',
103
+ 'vaping',
104
+ 'lottery',
105
+ 'clothing',
106
+ 'barberShop',
107
+ 'bar',
108
+ 'appliances',
109
+ 'repairShop',
110
+ 'spareParts',
111
+ 'gasStation',
112
+ 'realState',
113
+ 'travelAgency',
114
+ 'legal',
115
+ 'multipleServices',
116
+ 'academy',
117
+ 'training',
118
+ 'sportsShop',
119
+ 'gardenAndPets',
120
+ 'photos',
121
+ 'jewelryStore',
122
+ 'shoeShop',
123
+ 'nutritionStores',
124
+ 'moving',
125
+ 'dryCleaner',
126
+ 'toyStores',
127
+ 'other'
128
+ ],
129
+ });
130
+
131
+ const shop = () => ({
132
+ title: 'shop',
133
+ type: 'object',
134
+ properties: {
135
+ _id: uuid(),
136
+ createdAt: datetime(),
137
+ updatedAt: datetime(),
138
+ deletable: { type: 'boolean' },
139
+ readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
140
+ international: {
141
+ type: 'object',
142
+ properties: {
143
+ partnerKey: { type: 'string' },
144
+ parcelShopId: { type: 'string' },
145
+ },
146
+ required: ['partnerKey', 'parcelShopId'],
147
+ additionalProperties: false,
148
+ },
149
+ defaults: {
150
+ type: 'object',
151
+ properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
152
+ required: ['derivationSettings', 'expirationSettings'],
153
+ additionalProperties: false,
154
+ },
155
+ network: {
156
+ type: 'object',
157
+ properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
158
+ required: ['_id', 'name'],
159
+ additionalProperties: false,
160
+ },
161
+ zone: {
162
+ type: 'object',
163
+ properties: { ...pickProperties(zone(), ['_id', 'name']) },
164
+ required: ['_id', 'name'],
165
+ additionalProperties: false,
166
+ },
167
+ openingRepresentative: shopRepresentative(),
168
+ managingRepresentative: shopRepresentative(),
169
+ status: {
170
+ type: 'object',
171
+ properties: {
172
+ code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
173
+ disabled: {
174
+ type: 'object',
175
+ properties: {
176
+ at: datetime(),
177
+ reason: { type: 'string', trim: true },
178
+ },
179
+ required: ['at', 'reason'],
180
+ additionalProperties: false,
181
+ },
182
+ manuallyDisabled: {
183
+ type: 'object',
184
+ properties: {
185
+ at: datetime(),
186
+ reason: { type: 'string', trim: true },
187
+ },
188
+ required: ['at', 'reason'],
189
+ additionalProperties: false,
190
+ },
191
+ },
192
+ required: ['code'],
193
+ additionalProperties: false,
194
+ },
195
+ name: { type: 'string', trim: true },
196
+ address: addressWithRequiredLocation(),
197
+ capabilities: {
198
+ type: 'array',
199
+ items: { type: 'string', enum: ['deliver', 'pickup', 'sell'] },
200
+ uniqueItems: true,
201
+ },
202
+ openingSchedule: shopSchedule(),
203
+ timezone: timezone(),
204
+ contacts: {
205
+ type: 'array',
206
+ items: contact(),
207
+ },
208
+ fiscal: fiscal(),
209
+ activity: shopActivity(),
210
+ notes: { type: 'string', trim: true },
211
+ derivationSettings: derivationSettings(),
212
+ expirationSettings: expirationSettings(),
213
+ },
214
+ required: [
215
+ '_id',
216
+ 'createdAt',
217
+ 'updatedAt',
218
+ 'deletable',
219
+ 'readonly',
220
+ 'international',
221
+ 'defaults',
222
+ 'network',
223
+ 'status',
224
+ 'name',
225
+ 'address',
226
+ 'capabilities',
227
+ 'openingSchedule',
228
+ 'timezone',
229
+ 'contacts',
230
+ ],
231
+ additionalProperties: false,
232
+ });
233
+
234
+ const objectWithShopId = () => ({
235
+ type: 'object',
236
+ properties: { shop: objectWithUuid() },
237
+ required: ['shop'],
238
+ additionalProperties: false,
239
+ });
240
+
241
+ const setShopStatus = () => ({
242
+ type: 'object',
243
+ properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
244
+ additionalProperties: false,
245
+ });
246
+
247
+ const setShopRepresentative = () => ({
248
+ type: 'object',
249
+ properties: {
250
+ ...pickProperties(representative(), ['_id']),
251
+ since: datetime(),
252
+ },
253
+ required: ['_id', 'since'],
254
+ additionalProperties: false,
255
+ });
256
+
257
+ const createShopRequest = () =>
258
+ createRequest({
259
+ type: 'object',
260
+ properties: {
261
+ ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
262
+ network: objectWithUuid(),
263
+ zone: objectWithUuid(),
264
+ openingRepresentative: setShopRepresentative(),
265
+ managingRepresentative: setShopRepresentative(),
266
+ status: setShopStatus(),
267
+ ...pickProperties(shop(), [
268
+ 'name',
269
+ 'address',
270
+ 'capabilities',
271
+ 'openingSchedule',
272
+ 'timezone',
273
+ 'contacts',
274
+ 'fiscal',
275
+ 'activity',
276
+ 'notes',
277
+ 'derivationSettings',
278
+ 'expirationSettings',
279
+ ]),
280
+ },
281
+ required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
282
+ additionalProperties: false,
283
+ });
284
+
285
+ const createShopResponse = () => createResponse(shop());
286
+
287
+ const findByStatus = () => ({
288
+ title: 'find by status',
289
+ type: 'object',
290
+ properties: {
291
+ status: {
292
+ type: 'object',
293
+ properties: { ...pickProperties(shop().properties.status, ['code']) },
294
+ required: ['code'],
295
+ additionalProperties: false,
296
+ },
297
+ },
298
+ required: ['status'],
299
+ additionalProperties: false,
300
+ });
301
+
302
+ const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
303
+
304
+ const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
305
+
306
+ const findByStatusAndPolygonalArea = () =>
307
+ mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
308
+
309
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
310
+
311
+ const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
312
+
313
+ const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
314
+
315
+ const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
316
+
317
+ const findByNetworkAndStatusAndName = () =>
318
+ mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
319
+
320
+ const findByNetworkAndStatusAndCircularArea = () =>
321
+ mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
322
+
323
+ const findByNetworkAndStatusAndPolygonalArea = () =>
324
+ mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
325
+
326
+ const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
327
+
328
+ const findShopsSuperAdminRequest = () =>
329
+ findRequest({
330
+ oneOf: [
331
+ findAll(),
332
+ findById(),
333
+ findByStatus(),
334
+ findByName(),
335
+ findByAddress(),
336
+ findByStatusAndName(),
337
+ findByStatusAndCircularArea(),
338
+ findByStatusAndPolygonalArea(),
339
+ findByFiscal(),
340
+ findByNetwork(),
341
+ findByNetworkAndStatus(),
342
+ findByNetworkAndName(),
343
+ findByNetworkAndAddress(),
344
+ findByNetworkAndStatusAndName(),
345
+ findByNetworkAndStatusAndCircularArea(),
346
+ findByNetworkAndStatusAndPolygonalArea(),
347
+ findByNetworkAndFiscal(),
348
+ ],
349
+ });
350
+
351
+ const findShopsNetworkAdminRequest = () =>
352
+ findRequest({
353
+ oneOf: [
354
+ findAll(),
355
+ findById(),
356
+ findByStatus(),
357
+ findByName(),
358
+ findByAddress(),
359
+ findByStatusAndName(),
360
+ findByStatusAndCircularArea(),
361
+ findByStatusAndPolygonalArea(),
362
+ findByFiscal(),
363
+ ],
364
+ });
365
+
366
+ const findShopsResponse = () => findResponse(shop());
367
+
368
+ const updateShopRequest = () =>
369
+ updateRequest(
370
+ findById(),
371
+ {
372
+ type: 'object',
373
+ properties: {
374
+ zone: schemaOrNull(objectWithUuid()),
375
+ openingRepresentative: schemaOrNull(setShopRepresentative()),
376
+ managingRepresentative: schemaOrNull(setShopRepresentative()),
377
+ status: setShopStatus(),
378
+ ...pickProperties(
379
+ shop(),
380
+ ['name', 'address', 'capabilities', 'openingSchedule', 'contacts'],
381
+ ['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
382
+ ),
383
+ },
384
+ minProperties: 1,
385
+ additionalProperties: false,
386
+ },
387
+ {
388
+ type: 'object',
389
+ properties: { ...pickProperties(shop(), ['capabilities']) },
390
+ minProperties: 1,
391
+ additionalProperties: false,
392
+ },
393
+ );
394
+
395
+ const updateShopResponse = () => updateResponse(shop());
396
+
397
+ const deleteShopRequest = () => deleteRequest(findById());
398
+
399
+ const deleteShopResponse = () => deleteResponse(shop());
400
+
401
+ module.exports = {
402
+ shop,
403
+ objectWithShopId,
404
+ createShopRequest,
405
+ createShopResponse,
406
+ findShopsSuperAdminRequest,
407
+ findShopsNetworkAdminRequest,
408
+ findShopsResponse,
409
+ updateShopRequest,
410
+ updateShopResponse,
411
+ deleteShopRequest,
412
+ deleteShopResponse,
413
+ };