@gls_spain/gps-common 35.9.1 → 35.9.2

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/CHANGELOG.md CHANGED
@@ -1,17 +1,24 @@
1
- ## [35.9.1](https://github.com/GLS-Spain/gps-common/compare/v35.9.0...v35.9.1) (2024-11-07)
1
+ ## [35.9.2](https://github.com/GLS-Spain/gps-common/compare/v35.9.1...v35.9.2) (2024-11-13)
2
2
 
3
3
 
4
4
  ### Bug Fixes
5
5
 
6
- * add capacity to other models ([f421381](https://github.com/GLS-Spain/gps-common/commit/f4213810774a21f74194b4e63677381792173979))
7
-
8
- # [35.9.0](https://github.com/GLS-Spain/gps-common/compare/v35.8.2...v35.9.0) (2024-11-07)
9
-
10
-
11
- ### Features
12
-
13
- * field capacity ([301f737](https://github.com/GLS-Spain/gps-common/commit/301f737d9167d22f13c29f9d5641166c43189be7))
6
+ * delete maximum to clientCode ([4100b2c](https://github.com/GLS-Spain/gps-common/commit/4100b2c87d168d38d17ac836d9c21f1d64e8caf6))
14
7
 
8
+ ## [35.9.1](https://github.com/GLS-Spain/gps-common/compare/v35.9.0...v35.9.1) (2024-11-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add capacity to other models ([f421381](https://github.com/GLS-Spain/gps-common/commit/f4213810774a21f74194b4e63677381792173979))
14
+
15
+ # [35.9.0](https://github.com/GLS-Spain/gps-common/compare/v35.8.2...v35.9.0) (2024-11-07)
16
+
17
+
18
+ ### Features
19
+
20
+ * field capacity ([301f737](https://github.com/GLS-Spain/gps-common/commit/301f737d9167d22f13c29f9d5641166c43189be7))
21
+
15
22
  ## [35.8.2](https://github.com/GLS-Spain/gps-common/compare/v35.8.1...v35.8.2) (2024-10-17)
16
23
 
17
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gls_spain/gps-common",
3
- "version": "35.9.1",
3
+ "version": "35.9.2",
4
4
  "description": "Errors, schemas and documentation for the Parcel Shops project",
5
5
  "keywords": [
6
6
  "gls"
@@ -1,561 +1,560 @@
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
- findByIdInternational,
31
- } = require('./common');
32
- const { network, objectWithNetworkId } = require('./networks');
33
- const { defaults, derivationSettings, expirationSettings } = require('./defaults');
34
- const { zone } = require('./zones');
35
- const { representative } = require('./representatives');
36
-
37
- const shopDaySchedule = () => ({
38
- title: 'array of time ranges',
39
- type: 'array',
40
- items: timeRange(),
41
- minItems: 0,
42
- maxItems: 2,
43
- additionalProperties: false,
44
- description: '[ ] or [ [HH:mm:ss, HH:mm:ss] ] or [ [HH:mm:ss, HH:mm:ss], [HH:mm:ss, HH:mm:ss] ]',
45
- });
46
-
47
- const shopSchedule = () => ({
48
- oneOf: [
49
- {
50
- title: 'weekly schedule',
51
- type: 'object',
52
- properties: {
53
- type: { type: 'string', enum: ['weekly'] },
54
- weekly: shopDaySchedule(),
55
- saturday: shopDaySchedule(),
56
- },
57
- required: ['type', 'weekly', 'saturday'],
58
- additionalProperties: false,
59
- },
60
- {
61
- title: 'daily schedule',
62
- type: 'object',
63
- properties: {
64
- type: { type: 'string', enum: ['daily'] },
65
- monday: shopDaySchedule(),
66
- tuesday: shopDaySchedule(),
67
- wednesday: shopDaySchedule(),
68
- thursday: shopDaySchedule(),
69
- friday: shopDaySchedule(),
70
- saturday: shopDaySchedule(),
71
- },
72
- required: ['type', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
73
- additionalProperties: false,
74
- },
75
- ],
76
- });
77
-
78
- const shopHoliday = () => ({
79
- title: 'Holidays shop',
80
- type: 'object',
81
- properties: {
82
- _id: uuid(),
83
- from: datetime(),
84
- to: datetime(),
85
- description: { type: 'string' },
86
- createAt: datetime(),
87
- _idHolidaysInternational: uuid(),
88
- },
89
- required: ['from', 'to', '_id', 'createAt'],
90
- additionalProperties: false,
91
- });
92
-
93
- /*
94
- 2024-05-28 JL+SB este esquema con "absences" no se está utilizando
95
-
96
- const absencesHolidaysShop = () => ({
97
- title: 'Absences holidays shop',
98
- type: 'object',
99
- properties: {
100
- _id: uuid(),
101
- from: datetime(),
102
- to: datetime(),
103
- description: { type: 'string' },
104
- createAt: datetime(),
105
- },
106
- required: ['from', 'to', '_id', 'createAt'],
107
- additionalProperties: false,
108
- });
109
-
110
- const shopHolidays = () => ({
111
- title: 'Holidays shop',
112
- type: 'array',
113
- properties: {
114
- absences: absencesHolidaysShop(),
115
- },
116
- required: ['absences'],
117
- additionalProperties: false,
118
- });
119
- */
120
-
121
- const shopRepresentative = () => ({
122
- type: 'object',
123
- properties: {
124
- ...pickProperties(representative(), ['_id', 'name']),
125
- since: datetime(),
126
- },
127
- required: ['_id', 'name', 'since'],
128
- additionalProperties: false,
129
- });
130
-
131
- const shopActivity = () => ({
132
- type: 'string',
133
- enum: [
134
- 'bookshop',
135
- 'press',
136
- 'bazaar',
137
- 'telecom',
138
- 'mobileAccessories',
139
- 'inkSupplies',
140
- 'computer',
141
- 'optics',
142
- 'pharmacy',
143
- 'herbalist',
144
- 'food',
145
- 'hardware',
146
- 'tobacco',
147
- 'vaping',
148
- 'lottery',
149
- 'clothing',
150
- 'barberShop',
151
- 'bar',
152
- 'appliances',
153
- 'repairShop',
154
- 'spareParts',
155
- 'gasStation',
156
- 'realState',
157
- 'travelAgency',
158
- 'legal',
159
- 'multipleServices',
160
- 'academy',
161
- 'training',
162
- 'sportsShop',
163
- 'gardenAndPets',
164
- 'photos',
165
- 'jewelryStore',
166
- 'shoeShop',
167
- 'nutritionStores',
168
- 'moving',
169
- 'dryCleaner',
170
- 'toyStores',
171
- 'other',
172
- ],
173
- });
174
-
175
- const shop = () => ({
176
- title: 'shop',
177
- type: 'object',
178
- properties: {
179
- _id: uuid(),
180
- createdAt: datetime(),
181
- updatedAt: datetime(),
182
- deletable: { type: 'boolean' },
183
- readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
184
- international: {
185
- type: 'object',
186
- properties: {
187
- partnerKey: { type: 'string' },
188
- parcelShopId: { type: 'string' },
189
- },
190
- required: ['partnerKey', 'parcelShopId'],
191
- additionalProperties: false,
192
- },
193
- defaults: {
194
- type: 'object',
195
- properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
196
- required: ['derivationSettings', 'expirationSettings'],
197
- additionalProperties: false,
198
- },
199
- network: {
200
- type: 'object',
201
- properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
202
- required: ['_id', 'name'],
203
- additionalProperties: false,
204
- },
205
- zone: {
206
- type: 'object',
207
- properties: { ...pickProperties(zone(), ['_id', 'name']) },
208
- required: ['_id', 'name'],
209
- additionalProperties: false,
210
- },
211
- openingRepresentative: shopRepresentative(),
212
- managingRepresentative: shopRepresentative(),
213
- status: {
214
- type: 'object',
215
- properties: {
216
- code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
217
- disabled: {
218
- type: 'object',
219
- properties: {
220
- at: datetime(),
221
- reason: { type: 'string', trim: true },
222
- },
223
- required: ['at', 'reason'],
224
- additionalProperties: false,
225
- },
226
- manuallyDisabled: {
227
- type: 'object',
228
- properties: {
229
- _id: uuid(),
230
- at: datetime(),
231
- to: datetime(),
232
- reason: { type: 'string', trim: true },
233
- },
234
- required: ['at', 'reason'],
235
- additionalProperties: false,
236
- },
237
- },
238
- required: ['code'],
239
- additionalProperties: false,
240
- },
241
- name: { type: 'string', trim: true },
242
- address: addressWithRequiredLocation(),
243
- capabilities: {
244
- type: 'array',
245
- items: { type: 'string', enum: ['deliver', 'pickup', 'sell', 'sellplus'] },
246
- uniqueItems: true,
247
- },
248
-
249
- openingSchedule: shopSchedule(),
250
- holidays: { type: 'array', items: shopHoliday(), uniqueItems: true },
251
- timezone: timezone(),
252
- contacts: {
253
- type: 'array',
254
- items: contact(),
255
- },
256
- fiscal: fiscal(),
257
- activity: shopActivity(),
258
- notes: { type: 'string', trim: true },
259
- derivationSettings: derivationSettings(),
260
- expirationSettings: expirationSettings(),
261
- eco: { type: 'boolean', default: false },
262
- gold: { type: 'boolean', default: false },
263
- radical: { type: 'boolean', default: false },
264
- operations: { type: 'string', trim: true },
265
- reverseLogistic: { type: 'boolean', default: false },
266
- // squareCode: { type: 'string' },
267
- // clientCode: { type: 'string' },
268
- // 2023-01-12 JL están definidos como string
269
- // TODO en el momento que el frontend sea capaz de mandar integer, se quita "string"
270
- squareCode: { type: ['integer', 'string'], minimum: 0, maximum: 32767, description: 'agency code' },
271
- clientCode: { type: ['integer', 'string'], minimum: 0, maximum: 32767, description: 'client code' },
272
- // 2024-07-22 JJC campo de agencia de canalización
273
- channelingAgencyCode: { type: ['integer', 'string', 'null'], description: 'Channeling Agency Code' },
274
- //Volume capacity 07/11/2024
275
- capacity: { type: 'string' },
276
- },
277
- required: [
278
- '_id',
279
- 'createdAt',
280
- 'updatedAt',
281
- 'deletable',
282
- 'readonly',
283
- 'international',
284
- 'defaults',
285
- 'network',
286
- 'status',
287
- 'name',
288
- 'address',
289
- 'capabilities',
290
- 'openingSchedule',
291
- 'timezone',
292
- 'contacts',
293
- ],
294
- additionalProperties: false,
295
- });
296
-
297
- const objectWithShopId = () => ({
298
- type: 'object',
299
- properties: { shop: objectWithUuid() },
300
- required: ['shop'],
301
- additionalProperties: false,
302
- });
303
-
304
- const setShopStatus = () => ({
305
- type: 'object',
306
- properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
307
- additionalProperties: false,
308
- });
309
-
310
- const setShopRepresentative = () => ({
311
- type: 'object',
312
- properties: {
313
- ...pickProperties(representative(), ['_id']),
314
- since: datetime(),
315
- },
316
- required: ['_id', 'since'],
317
- additionalProperties: false,
318
- });
319
-
320
- const createShopRequest = () =>
321
- createRequest({
322
- type: 'object',
323
- properties: {
324
- ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
325
- network: objectWithUuid(),
326
- zone: objectWithUuid(),
327
- openingRepresentative: setShopRepresentative(),
328
- managingRepresentative: setShopRepresentative(),
329
- status: setShopStatus(),
330
- ...pickProperties(shop(), [
331
- 'name',
332
- 'address',
333
- 'capabilities',
334
- 'openingSchedule',
335
- 'timezone',
336
- 'contacts',
337
- 'fiscal',
338
- 'activity',
339
- 'notes',
340
- 'derivationSettings',
341
- 'expirationSettings',
342
- 'eco',
343
- 'gold',
344
- 'radical',
345
- 'operations',
346
- 'reverseLogistic',
347
- 'capacity',
348
- 'squareCode',
349
- 'clientCode',
350
- 'channelingAgencyCode',
351
- ]),
352
- },
353
- required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
354
- additionalProperties: false,
355
- });
356
-
357
- const createShopResponse = () => createResponse(shop());
358
-
359
- const findByStatus = () => ({
360
- title: 'find by status',
361
- type: 'object',
362
- properties: {
363
- status: {
364
- type: 'object',
365
- properties: { ...pickProperties(shop().properties.status, ['code']) },
366
- required: ['code'],
367
- additionalProperties: false,
368
- },
369
- },
370
- required: ['status'],
371
- additionalProperties: false,
372
- });
373
-
374
- const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
375
-
376
- const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
377
-
378
- const findByStatusAndPolygonalArea = () =>
379
- mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
380
-
381
- const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
382
-
383
- const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
384
-
385
- const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
386
-
387
- const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
388
-
389
- const findByNetworkAndStatusAndName = () =>
390
- mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
391
-
392
- const findByNetworkAndStatusAndCircularArea = () =>
393
- mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
394
-
395
- const findByNetworkAndStatusAndPolygonalArea = () =>
396
- mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
397
-
398
- const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
399
-
400
- // const findByInternationalPartnerKey = () => mergeSchemas(findByIdInternational(), { title: 'find by International PartnerKey' });
401
-
402
-
403
- const findShopsSuperAdminRequest = () =>
404
- findRequest({
405
- oneOf: [
406
- findAll(),
407
- findById(),
408
- findByStatus(),
409
- findByName(),
410
- findByAddress(),
411
- findByStatusAndName(),
412
- findByStatusAndCircularArea(),
413
- findByStatusAndPolygonalArea(),
414
- findByFiscal(),
415
- findByNetwork(),
416
- findByNetworkAndStatus(),
417
- findByNetworkAndName(),
418
- findByNetworkAndAddress(),
419
- findByNetworkAndStatusAndName(),
420
- findByNetworkAndStatusAndCircularArea(),
421
- findByNetworkAndStatusAndPolygonalArea(),
422
- findByNetworkAndFiscal(),
423
- findByIdInternational(),
424
- // findByInternationalPartnerKey(),
425
- ],
426
- });
427
-
428
- const findShopsNetworkAdminRequest = () =>
429
- findRequest({
430
- oneOf: [
431
- findAll(),
432
- findById(),
433
- findByStatus(),
434
- findByName(),
435
- findByAddress(),
436
- findByStatusAndName(),
437
- findByStatusAndCircularArea(),
438
- findByStatusAndPolygonalArea(),
439
- findByFiscal(),
440
- findByIdInternational(),
441
- ],
442
- });
443
-
444
- const findShopsResponse = () => findResponse(shop());
445
-
446
- const updateShopRequest = () =>
447
- updateRequest(
448
- findById(),
449
- {
450
- type: 'object',
451
- properties: {
452
- network: schemaOrNull(objectWithUuid()),
453
- zone: schemaOrNull(objectWithUuid()),
454
- openingRepresentative: schemaOrNull(setShopRepresentative()),
455
- managingRepresentative: schemaOrNull(setShopRepresentative()),
456
- status: setShopStatus(),
457
- ...pickProperties(
458
- shop(),
459
- [
460
- 'name',
461
- 'address',
462
- 'capabilities',
463
- 'openingSchedule',
464
- 'holidays',
465
- 'contacts',
466
- 'eco',
467
- 'gold',
468
- 'radical',
469
- 'operations',
470
- 'reverseLogistic',
471
- 'capacity',
472
- 'squareCode',
473
- 'clientCode',
474
- 'channelingAgencyCode'
475
- ],
476
- ['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
477
- ),
478
- },
479
- minProperties: 0,
480
- additionalProperties: false,
481
- },
482
- {
483
- type: 'object',
484
- properties: { ...pickProperties(shop(), ['capabilities']) },
485
- minProperties: 1,
486
- additionalProperties: false,
487
- },
488
- );
489
-
490
- const updateShopResponse = () => updateResponse(shop());
491
-
492
- const deleteShopRequest = () => deleteRequest(findById());
493
-
494
- const deleteShopResponse = () => deleteResponse(shop());
495
-
496
- const upsertShopRequest = () => ({
497
- type: 'object',
498
- properties: {
499
- upsert: {
500
- title: 'upsert',
501
- type: 'object',
502
- properties: {
503
- ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
504
- network: objectWithUuid(),
505
- zone: objectWithUuid(),
506
- openingRepresentative: setShopRepresentative(),
507
- managingRepresentative: setShopRepresentative(),
508
- status: setShopStatus(),
509
- ...pickProperties(shop(), [
510
- 'name',
511
- 'address',
512
- 'capabilities',
513
- 'openingSchedule',
514
- 'timezone',
515
- 'contacts',
516
- 'fiscal',
517
- 'activity',
518
- 'notes',
519
- 'derivationSettings',
520
- 'expirationSettings',
521
- 'eco',
522
- 'gold',
523
- 'radical',
524
- 'operations',
525
- 'reverseLogistic',
526
- 'capacity',
527
- 'squareCode',
528
- 'clientCode',
529
- 'channelingAgencyCode',
530
- ]),
531
- },
532
- required: ['network', 'status', 'name', 'address'],
533
- additionalProperties: false,
534
- },
535
- },
536
- required: ['upsert'],
537
- additionalProperties: false,
538
- });
539
-
540
- const upsertShopResponse = () => ({
541
- type: 'object',
542
- properties: { upsert: shop() },
543
- required: ['upsert'],
544
- additionalProperties: false,
545
- });
546
-
547
- module.exports = {
548
- shop,
549
- objectWithShopId,
550
- createShopRequest,
551
- createShopResponse,
552
- findShopsSuperAdminRequest,
553
- findShopsNetworkAdminRequest,
554
- findShopsResponse,
555
- updateShopRequest,
556
- updateShopResponse,
557
- deleteShopRequest,
558
- deleteShopResponse,
559
- upsertShopResponse,
560
- upsertShopRequest,
561
- };
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
+ findByIdInternational,
31
+ } = require('./common');
32
+ const { network, objectWithNetworkId } = require('./networks');
33
+ const { defaults, derivationSettings, expirationSettings } = require('./defaults');
34
+ const { zone } = require('./zones');
35
+ const { representative } = require('./representatives');
36
+
37
+ const shopDaySchedule = () => ({
38
+ title: 'array of time ranges',
39
+ type: 'array',
40
+ items: timeRange(),
41
+ minItems: 0,
42
+ maxItems: 2,
43
+ additionalProperties: false,
44
+ description: '[ ] or [ [HH:mm:ss, HH:mm:ss] ] or [ [HH:mm:ss, HH:mm:ss], [HH:mm:ss, HH:mm:ss] ]',
45
+ });
46
+
47
+ const shopSchedule = () => ({
48
+ oneOf: [
49
+ {
50
+ title: 'weekly schedule',
51
+ type: 'object',
52
+ properties: {
53
+ type: { type: 'string', enum: ['weekly'] },
54
+ weekly: shopDaySchedule(),
55
+ saturday: shopDaySchedule(),
56
+ },
57
+ required: ['type', 'weekly', 'saturday'],
58
+ additionalProperties: false,
59
+ },
60
+ {
61
+ title: 'daily schedule',
62
+ type: 'object',
63
+ properties: {
64
+ type: { type: 'string', enum: ['daily'] },
65
+ monday: shopDaySchedule(),
66
+ tuesday: shopDaySchedule(),
67
+ wednesday: shopDaySchedule(),
68
+ thursday: shopDaySchedule(),
69
+ friday: shopDaySchedule(),
70
+ saturday: shopDaySchedule(),
71
+ },
72
+ required: ['type', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
73
+ additionalProperties: false,
74
+ },
75
+ ],
76
+ });
77
+
78
+ const shopHoliday = () => ({
79
+ title: 'Holidays shop',
80
+ type: 'object',
81
+ properties: {
82
+ _id: uuid(),
83
+ from: datetime(),
84
+ to: datetime(),
85
+ description: { type: 'string' },
86
+ createAt: datetime(),
87
+ _idHolidaysInternational: uuid(),
88
+ },
89
+ required: ['from', 'to', '_id', 'createAt'],
90
+ additionalProperties: false,
91
+ });
92
+
93
+ /*
94
+ 2024-05-28 JL+SB este esquema con "absences" no se está utilizando
95
+
96
+ const absencesHolidaysShop = () => ({
97
+ title: 'Absences holidays shop',
98
+ type: 'object',
99
+ properties: {
100
+ _id: uuid(),
101
+ from: datetime(),
102
+ to: datetime(),
103
+ description: { type: 'string' },
104
+ createAt: datetime(),
105
+ },
106
+ required: ['from', 'to', '_id', 'createAt'],
107
+ additionalProperties: false,
108
+ });
109
+
110
+ const shopHolidays = () => ({
111
+ title: 'Holidays shop',
112
+ type: 'array',
113
+ properties: {
114
+ absences: absencesHolidaysShop(),
115
+ },
116
+ required: ['absences'],
117
+ additionalProperties: false,
118
+ });
119
+ */
120
+
121
+ const shopRepresentative = () => ({
122
+ type: 'object',
123
+ properties: {
124
+ ...pickProperties(representative(), ['_id', 'name']),
125
+ since: datetime(),
126
+ },
127
+ required: ['_id', 'name', 'since'],
128
+ additionalProperties: false,
129
+ });
130
+
131
+ const shopActivity = () => ({
132
+ type: 'string',
133
+ enum: [
134
+ 'bookshop',
135
+ 'press',
136
+ 'bazaar',
137
+ 'telecom',
138
+ 'mobileAccessories',
139
+ 'inkSupplies',
140
+ 'computer',
141
+ 'optics',
142
+ 'pharmacy',
143
+ 'herbalist',
144
+ 'food',
145
+ 'hardware',
146
+ 'tobacco',
147
+ 'vaping',
148
+ 'lottery',
149
+ 'clothing',
150
+ 'barberShop',
151
+ 'bar',
152
+ 'appliances',
153
+ 'repairShop',
154
+ 'spareParts',
155
+ 'gasStation',
156
+ 'realState',
157
+ 'travelAgency',
158
+ 'legal',
159
+ 'multipleServices',
160
+ 'academy',
161
+ 'training',
162
+ 'sportsShop',
163
+ 'gardenAndPets',
164
+ 'photos',
165
+ 'jewelryStore',
166
+ 'shoeShop',
167
+ 'nutritionStores',
168
+ 'moving',
169
+ 'dryCleaner',
170
+ 'toyStores',
171
+ 'other',
172
+ ],
173
+ });
174
+
175
+ const shop = () => ({
176
+ title: 'shop',
177
+ type: 'object',
178
+ properties: {
179
+ _id: uuid(),
180
+ createdAt: datetime(),
181
+ updatedAt: datetime(),
182
+ deletable: { type: 'boolean' },
183
+ readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
184
+ international: {
185
+ type: 'object',
186
+ properties: {
187
+ partnerKey: { type: 'string' },
188
+ parcelShopId: { type: 'string' },
189
+ },
190
+ required: ['partnerKey', 'parcelShopId'],
191
+ additionalProperties: false,
192
+ },
193
+ defaults: {
194
+ type: 'object',
195
+ properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
196
+ required: ['derivationSettings', 'expirationSettings'],
197
+ additionalProperties: false,
198
+ },
199
+ network: {
200
+ type: 'object',
201
+ properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
202
+ required: ['_id', 'name'],
203
+ additionalProperties: false,
204
+ },
205
+ zone: {
206
+ type: 'object',
207
+ properties: { ...pickProperties(zone(), ['_id', 'name']) },
208
+ required: ['_id', 'name'],
209
+ additionalProperties: false,
210
+ },
211
+ openingRepresentative: shopRepresentative(),
212
+ managingRepresentative: shopRepresentative(),
213
+ status: {
214
+ type: 'object',
215
+ properties: {
216
+ code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
217
+ disabled: {
218
+ type: 'object',
219
+ properties: {
220
+ at: datetime(),
221
+ reason: { type: 'string', trim: true },
222
+ },
223
+ required: ['at', 'reason'],
224
+ additionalProperties: false,
225
+ },
226
+ manuallyDisabled: {
227
+ type: 'object',
228
+ properties: {
229
+ _id: uuid(),
230
+ at: datetime(),
231
+ to: datetime(),
232
+ reason: { type: 'string', trim: true },
233
+ },
234
+ required: ['at', 'reason'],
235
+ additionalProperties: false,
236
+ },
237
+ },
238
+ required: ['code'],
239
+ additionalProperties: false,
240
+ },
241
+ name: { type: 'string', trim: true },
242
+ address: addressWithRequiredLocation(),
243
+ capabilities: {
244
+ type: 'array',
245
+ items: { type: 'string', enum: ['deliver', 'pickup', 'sell', 'sellplus'] },
246
+ uniqueItems: true,
247
+ },
248
+
249
+ openingSchedule: shopSchedule(),
250
+ holidays: { type: 'array', items: shopHoliday(), uniqueItems: true },
251
+ timezone: timezone(),
252
+ contacts: {
253
+ type: 'array',
254
+ items: contact(),
255
+ },
256
+ fiscal: fiscal(),
257
+ activity: shopActivity(),
258
+ notes: { type: 'string', trim: true },
259
+ derivationSettings: derivationSettings(),
260
+ expirationSettings: expirationSettings(),
261
+ eco: { type: 'boolean', default: false },
262
+ gold: { type: 'boolean', default: false },
263
+ radical: { type: 'boolean', default: false },
264
+ operations: { type: 'string', trim: true },
265
+ reverseLogistic: { type: 'boolean', default: false },
266
+ // squareCode: { type: 'string' },
267
+ // clientCode: { type: 'string' },
268
+ // 2023-01-12 JL están definidos como string
269
+ // TODO en el momento que el frontend sea capaz de mandar integer, se quita "string"
270
+ squareCode: { type: ['integer', 'string'], minimum: 0, maximum: 32767, description: 'agency code' },
271
+ // 2024-07-22 JJC campo de agencia de canalización
272
+ channelingAgencyCode: { type: ['integer', 'string', 'null'], description: 'Channeling Agency Code' },
273
+ //Volume capacity 07/11/2024
274
+ capacity: { type: 'string' },
275
+ },
276
+ required: [
277
+ '_id',
278
+ 'createdAt',
279
+ 'updatedAt',
280
+ 'deletable',
281
+ 'readonly',
282
+ 'international',
283
+ 'defaults',
284
+ 'network',
285
+ 'status',
286
+ 'name',
287
+ 'address',
288
+ 'capabilities',
289
+ 'openingSchedule',
290
+ 'timezone',
291
+ 'contacts',
292
+ ],
293
+ additionalProperties: false,
294
+ });
295
+
296
+ const objectWithShopId = () => ({
297
+ type: 'object',
298
+ properties: { shop: objectWithUuid() },
299
+ required: ['shop'],
300
+ additionalProperties: false,
301
+ });
302
+
303
+ const setShopStatus = () => ({
304
+ type: 'object',
305
+ properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
306
+ additionalProperties: false,
307
+ });
308
+
309
+ const setShopRepresentative = () => ({
310
+ type: 'object',
311
+ properties: {
312
+ ...pickProperties(representative(), ['_id']),
313
+ since: datetime(),
314
+ },
315
+ required: ['_id', 'since'],
316
+ additionalProperties: false,
317
+ });
318
+
319
+ const createShopRequest = () =>
320
+ createRequest({
321
+ type: 'object',
322
+ properties: {
323
+ ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
324
+ network: objectWithUuid(),
325
+ zone: objectWithUuid(),
326
+ openingRepresentative: setShopRepresentative(),
327
+ managingRepresentative: setShopRepresentative(),
328
+ status: setShopStatus(),
329
+ ...pickProperties(shop(), [
330
+ 'name',
331
+ 'address',
332
+ 'capabilities',
333
+ 'openingSchedule',
334
+ 'timezone',
335
+ 'contacts',
336
+ 'fiscal',
337
+ 'activity',
338
+ 'notes',
339
+ 'derivationSettings',
340
+ 'expirationSettings',
341
+ 'eco',
342
+ 'gold',
343
+ 'radical',
344
+ 'operations',
345
+ 'reverseLogistic',
346
+ 'capacity',
347
+ 'squareCode',
348
+ 'clientCode',
349
+ 'channelingAgencyCode',
350
+ ]),
351
+ },
352
+ required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
353
+ additionalProperties: false,
354
+ });
355
+
356
+ const createShopResponse = () => createResponse(shop());
357
+
358
+ const findByStatus = () => ({
359
+ title: 'find by status',
360
+ type: 'object',
361
+ properties: {
362
+ status: {
363
+ type: 'object',
364
+ properties: { ...pickProperties(shop().properties.status, ['code']) },
365
+ required: ['code'],
366
+ additionalProperties: false,
367
+ },
368
+ },
369
+ required: ['status'],
370
+ additionalProperties: false,
371
+ });
372
+
373
+ const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
374
+
375
+ const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
376
+
377
+ const findByStatusAndPolygonalArea = () =>
378
+ mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
379
+
380
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
381
+
382
+ const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
383
+
384
+ const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
385
+
386
+ const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
387
+
388
+ const findByNetworkAndStatusAndName = () =>
389
+ mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
390
+
391
+ const findByNetworkAndStatusAndCircularArea = () =>
392
+ mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
393
+
394
+ const findByNetworkAndStatusAndPolygonalArea = () =>
395
+ mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
396
+
397
+ const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
398
+
399
+ // const findByInternationalPartnerKey = () => mergeSchemas(findByIdInternational(), { title: 'find by International PartnerKey' });
400
+
401
+
402
+ const findShopsSuperAdminRequest = () =>
403
+ findRequest({
404
+ oneOf: [
405
+ findAll(),
406
+ findById(),
407
+ findByStatus(),
408
+ findByName(),
409
+ findByAddress(),
410
+ findByStatusAndName(),
411
+ findByStatusAndCircularArea(),
412
+ findByStatusAndPolygonalArea(),
413
+ findByFiscal(),
414
+ findByNetwork(),
415
+ findByNetworkAndStatus(),
416
+ findByNetworkAndName(),
417
+ findByNetworkAndAddress(),
418
+ findByNetworkAndStatusAndName(),
419
+ findByNetworkAndStatusAndCircularArea(),
420
+ findByNetworkAndStatusAndPolygonalArea(),
421
+ findByNetworkAndFiscal(),
422
+ findByIdInternational(),
423
+ // findByInternationalPartnerKey(),
424
+ ],
425
+ });
426
+
427
+ const findShopsNetworkAdminRequest = () =>
428
+ findRequest({
429
+ oneOf: [
430
+ findAll(),
431
+ findById(),
432
+ findByStatus(),
433
+ findByName(),
434
+ findByAddress(),
435
+ findByStatusAndName(),
436
+ findByStatusAndCircularArea(),
437
+ findByStatusAndPolygonalArea(),
438
+ findByFiscal(),
439
+ findByIdInternational(),
440
+ ],
441
+ });
442
+
443
+ const findShopsResponse = () => findResponse(shop());
444
+
445
+ const updateShopRequest = () =>
446
+ updateRequest(
447
+ findById(),
448
+ {
449
+ type: 'object',
450
+ properties: {
451
+ network: schemaOrNull(objectWithUuid()),
452
+ zone: schemaOrNull(objectWithUuid()),
453
+ openingRepresentative: schemaOrNull(setShopRepresentative()),
454
+ managingRepresentative: schemaOrNull(setShopRepresentative()),
455
+ status: setShopStatus(),
456
+ ...pickProperties(
457
+ shop(),
458
+ [
459
+ 'name',
460
+ 'address',
461
+ 'capabilities',
462
+ 'openingSchedule',
463
+ 'holidays',
464
+ 'contacts',
465
+ 'eco',
466
+ 'gold',
467
+ 'radical',
468
+ 'operations',
469
+ 'reverseLogistic',
470
+ 'capacity',
471
+ 'squareCode',
472
+ 'clientCode',
473
+ 'channelingAgencyCode'
474
+ ],
475
+ ['fiscal', 'activity', 'notes', 'derivationSettings', 'expirationSettings'],
476
+ ),
477
+ },
478
+ minProperties: 0,
479
+ additionalProperties: false,
480
+ },
481
+ {
482
+ type: 'object',
483
+ properties: { ...pickProperties(shop(), ['capabilities']) },
484
+ minProperties: 1,
485
+ additionalProperties: false,
486
+ },
487
+ );
488
+
489
+ const updateShopResponse = () => updateResponse(shop());
490
+
491
+ const deleteShopRequest = () => deleteRequest(findById());
492
+
493
+ const deleteShopResponse = () => deleteResponse(shop());
494
+
495
+ const upsertShopRequest = () => ({
496
+ type: 'object',
497
+ properties: {
498
+ upsert: {
499
+ title: 'upsert',
500
+ type: 'object',
501
+ properties: {
502
+ ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
503
+ network: objectWithUuid(),
504
+ zone: objectWithUuid(),
505
+ openingRepresentative: setShopRepresentative(),
506
+ managingRepresentative: setShopRepresentative(),
507
+ status: setShopStatus(),
508
+ ...pickProperties(shop(), [
509
+ 'name',
510
+ 'address',
511
+ 'capabilities',
512
+ 'openingSchedule',
513
+ 'timezone',
514
+ 'contacts',
515
+ 'fiscal',
516
+ 'activity',
517
+ 'notes',
518
+ 'derivationSettings',
519
+ 'expirationSettings',
520
+ 'eco',
521
+ 'gold',
522
+ 'radical',
523
+ 'operations',
524
+ 'reverseLogistic',
525
+ 'capacity',
526
+ 'squareCode',
527
+ 'clientCode',
528
+ 'channelingAgencyCode',
529
+ ]),
530
+ },
531
+ required: ['network', 'status', 'name', 'address'],
532
+ additionalProperties: false,
533
+ },
534
+ },
535
+ required: ['upsert'],
536
+ additionalProperties: false,
537
+ });
538
+
539
+ const upsertShopResponse = () => ({
540
+ type: 'object',
541
+ properties: { upsert: shop() },
542
+ required: ['upsert'],
543
+ additionalProperties: false,
544
+ });
545
+
546
+ module.exports = {
547
+ shop,
548
+ objectWithShopId,
549
+ createShopRequest,
550
+ createShopResponse,
551
+ findShopsSuperAdminRequest,
552
+ findShopsNetworkAdminRequest,
553
+ findShopsResponse,
554
+ updateShopRequest,
555
+ updateShopResponse,
556
+ deleteShopRequest,
557
+ deleteShopResponse,
558
+ upsertShopResponse,
559
+ upsertShopRequest,
560
+ };