@gls_spain/gps-common 27.1.1 → 28.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gls_spain/gps-common",
3
- "version": "27.1.1",
3
+ "version": "28.0.0",
4
4
  "description": "Errors, schemas and documentation for the Parcel Shops project",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -27,28 +27,28 @@
27
27
  }
28
28
  },
29
29
  "devDependencies": {
30
- "@semantic-release/changelog": "latest",
31
- "@semantic-release/git": "latest",
30
+ "@semantic-release/changelog": "^5.0.0",
31
+ "@semantic-release/git": "^9.0.0",
32
32
  "@semantic-release/npm": "^7.0.3",
33
- "@semantic-release/release-notes-generator": "latest",
34
- "@types/jest": "^25.1.2",
33
+ "@semantic-release/release-notes-generator": "^9.0.0",
34
+ "@types/jest": "^25.1.3",
35
35
  "ajv": "^6.11.0",
36
- "commitizen": "latest",
37
- "cz-conventional-changelog": "latest",
38
- "eslint": "latest",
39
- "eslint-config-airbnb-base": "latest",
40
- "eslint-config-prettier": "latest",
36
+ "commitizen": "^4.0.3",
37
+ "cz-conventional-changelog": "^3.1.0",
38
+ "eslint": "^6.8.0",
39
+ "eslint-config-airbnb-base": "^14.0.0",
40
+ "eslint-config-prettier": "^6.10.0",
41
41
  "eslint-plugin-import": "^2.20.1",
42
42
  "husky": "^4.2.3",
43
- "jest": "latest",
44
- "prettier": "latest",
43
+ "jest": "^25.1.0",
44
+ "prettier": "^1.19.1",
45
45
  "redoc-cli": "^0.9.6",
46
46
  "semantic-release": "^17.0.4"
47
47
  },
48
48
  "dependencies": {
49
- "@gls_spain/ajv-options": "^1.0.0",
49
+ "@gls_spain/ajv-options": "^1.1.0",
50
50
  "@gls_spain/common-errors": "^1.0.0",
51
- "@gls_spain/common-json-schemas": "^1.0.0",
51
+ "@gls_spain/common-json-schemas": "^1.1.0",
52
52
  "@gls_spain/winston-transports": "^1.0.0",
53
53
  "lodash": "^4.17.15",
54
54
  "winston": "^3.2.1",
@@ -47,7 +47,9 @@ const findByName = () => ({
47
47
  const findByAddress = () => ({
48
48
  title: 'find by address',
49
49
  type: 'object',
50
- properties: { address: { type: 'string', minLength: 3, description: 'search in address fields' } },
50
+ properties: {
51
+ address: { type: 'string', minLength: 3, description: 'search in address street, postal code, locality and administrative area' },
52
+ },
51
53
  required: ['address'],
52
54
  additionalProperties: false,
53
55
  });
@@ -104,7 +106,7 @@ const objectWithUuidAndName = () => ({
104
106
 
105
107
  const tags = () => ({
106
108
  type: 'array',
107
- items: { type: 'string' },
109
+ items: { type: 'string', trim: true },
108
110
  uniqueItems: true,
109
111
  });
110
112
 
@@ -112,7 +114,7 @@ const contact = () => ({
112
114
  title: 'contact',
113
115
  type: 'object',
114
116
  properties: {
115
- name: { type: 'string' },
117
+ name: { type: 'string', trim: true },
116
118
  email: email(),
117
119
  phone: phone(),
118
120
  },
@@ -124,9 +126,9 @@ const fiscal = () => ({
124
126
  title: 'fiscal data',
125
127
  type: 'object',
126
128
  properties: {
127
- iban: { type: 'string' },
128
- businessName: { type: 'string' },
129
- nif: { type: 'string' },
129
+ iban: { type: 'string', trim: true },
130
+ businessName: { type: 'string', trim: true },
131
+ nif: { type: 'string', trim: true },
130
132
  contacts: {
131
133
  type: 'array',
132
134
  items: contact(),
@@ -134,7 +136,7 @@ const fiscal = () => ({
134
136
  address: address(),
135
137
  paymentMethod: { type: 'string', enum: ['transfer', 'confirming'] },
136
138
  dueDays: { type: 'integer', minimum: 0 },
137
- activity: { type: 'string', description: 'IAE' },
139
+ activity: { type: 'string', trim: true, description: 'IAE' },
138
140
  retention: { type: 'integer', description: 'invoice retention percentage' },
139
141
  },
140
142
  required: ['iban', 'businessName', 'nif', 'contacts', 'address', 'paymentMethod', 'dueDays', 'activity', 'retention'],
@@ -144,7 +146,7 @@ const fiscal = () => ({
144
146
  const findByFiscal = () => ({
145
147
  title: 'find by fiscal',
146
148
  type: 'object',
147
- properties: { fiscal: { type: 'string', minLength: 3, description: 'search by fiscal data' } },
149
+ properties: { fiscal: { type: 'string', minLength: 3, description: 'search in business name and nif' } },
148
150
  required: ['fiscal'],
149
151
  additionalProperties: false,
150
152
  });
@@ -19,7 +19,7 @@ const {
19
19
  } = require('@gls_spain/common-json-schemas');
20
20
  const { date, findById, findByIds, tags } = require('./common');
21
21
  const { address } = require('./common');
22
- const { network } = require('./networks');
22
+ const { network, objectWithNetworkId } = require('./networks');
23
23
  const { shop, objectWithShopId } = require('./shops');
24
24
  const { derivationSettings } = require('./defaults');
25
25
 
@@ -34,12 +34,12 @@ const expeditionAddress = () => ({
34
34
  title: 'expedition address',
35
35
  type: 'object',
36
36
  properties: {
37
- name: { type: 'string' },
38
- contact: { type: 'string' },
39
- department: { type: 'string' },
37
+ name: { type: 'string', trim: true },
38
+ contact: { type: 'string', trim: true },
39
+ department: { type: 'string', trim: true },
40
40
  emails: { type: 'array', items: email(), uniqueItems: true },
41
41
  phones: { type: 'array', items: phone(), uniqueItems: true },
42
- nif: { type: 'string' },
42
+ nif: { type: 'string', trim: true },
43
43
  address: address(),
44
44
  agency: objectWithAgencyCode(),
45
45
  },
@@ -51,9 +51,9 @@ const driver = () => ({
51
51
  title: 'driver',
52
52
  type: 'object',
53
53
  properties: {
54
- agency: { type: 'string' },
55
- code: { type: 'string' },
56
- device: { type: 'string' },
54
+ agency: { type: 'string', trim: true },
55
+ code: { type: 'string', trim: true },
56
+ device: { type: 'string', trim: true },
57
57
  },
58
58
  required: ['agency', 'code', 'device'],
59
59
  additionalProperties: false,
@@ -63,8 +63,8 @@ const customer = () => ({
63
63
  title: 'customer',
64
64
  type: 'object',
65
65
  properties: {
66
- name: { type: 'string' },
67
- nif: { type: 'string' },
66
+ name: { type: 'string', trim: true },
67
+ nif: { type: 'string', trim: true },
68
68
  pod: objectWithUuid(),
69
69
  },
70
70
  required: ['name', 'nif', 'pod'],
@@ -74,8 +74,8 @@ const customer = () => ({
74
74
  const customerWithPod = () => ({
75
75
  type: 'object',
76
76
  properties: {
77
- name: { type: 'string' },
78
- nif: { type: 'string' },
77
+ name: { type: 'string', trim: true },
78
+ nif: { type: 'string', trim: true },
79
79
  pod: { type: 'string', contentMediaType: 'image/jpg', contentEncoding: 'base64' },
80
80
  },
81
81
  required: ['name', 'nif', 'pod'],
@@ -134,6 +134,7 @@ const expedition = () => ({
134
134
  properties: { ...pickProperties(shop(), ['_id', 'name']) },
135
135
  required: ['_id', 'name'],
136
136
  additionalProperties: false,
137
+ description: 'not available for incoming expeditions that are not assigned to a shop until reception',
137
138
  },
138
139
  type: { type: 'string', enum: ['delivery', 'pickup', 'sale'] },
139
140
  status: {
@@ -199,7 +200,7 @@ const expedition = () => ({
199
200
  additionalProperties: false,
200
201
  description: 'only available for deliveries and pickups after reception at the shop',
201
202
  },
202
- barcodes: { type: 'array', items: { type: 'string' } },
203
+ barcodes: { type: 'array', items: { type: 'string', trim: true } },
203
204
  packageCount: { type: 'integer' },
204
205
  weight: { type: 'number' },
205
206
  volume: { type: 'number' },
@@ -211,11 +212,11 @@ const expedition = () => ({
211
212
  type: 'object',
212
213
  properties: {
213
214
  code: { type: 'integer' },
214
- name: { type: 'string' },
215
- contact: { type: 'string' },
215
+ name: { type: 'string', trim: true },
216
+ contact: { type: 'string', trim: true },
216
217
  emails: { type: 'array', items: email(), uniqueItems: true },
217
218
  phones: { type: 'array', items: phone(), uniqueItems: true },
218
- openingSchedule: { type: 'string' },
219
+ openingSchedule: { type: 'string', trim: true },
219
220
  },
220
221
  required: ['code', 'name', 'emails', 'phones'],
221
222
  additionalProperties: false,
@@ -225,7 +226,7 @@ const expedition = () => ({
225
226
  type: 'object',
226
227
  properties: {
227
228
  code: { type: 'integer' },
228
- name: { type: 'string' },
229
+ name: { type: 'string', trim: true },
229
230
  agency: objectWithAgencyCode(),
230
231
  },
231
232
  required: ['code', 'name', 'agency'],
@@ -237,8 +238,8 @@ const expedition = () => ({
237
238
  title: 'expedition reference',
238
239
  type: 'object',
239
240
  properties: {
240
- type: { type: 'string' },
241
- value: { type: 'string' },
241
+ type: { type: 'string', trim: true },
242
+ value: { type: 'string', trim: true },
242
243
  },
243
244
  required: ['type', 'value'],
244
245
  additionalProperties: false,
@@ -252,7 +253,7 @@ const expedition = () => ({
252
253
  type: 'object',
253
254
  properties: {
254
255
  number: { type: 'integer', description: 'package number in expedition (1, 2, 3), can be sparse' },
255
- barcodes: { type: 'array', items: { type: 'string' } },
256
+ barcodes: { type: 'array', items: { type: 'string', trim: true } },
256
257
  weight: { type: 'number' },
257
258
  width: { type: 'number' },
258
259
  length: { type: 'number' },
@@ -262,7 +263,7 @@ const expedition = () => ({
262
263
  additionalProperties: false,
263
264
  },
264
265
  },
265
- notes: { type: 'string' },
266
+ notes: { type: 'string', trim: true },
266
267
  },
267
268
  required: [
268
269
  '_id',
@@ -270,7 +271,6 @@ const expedition = () => ({
270
271
  'updatedAt',
271
272
  'deletable',
272
273
  'network',
273
- 'shop',
274
274
  'type',
275
275
  'status',
276
276
  'code',
@@ -299,57 +299,114 @@ const objectWithExpeditionId = () => ({
299
299
  additionalProperties: false,
300
300
  });
301
301
 
302
- const createExpeditionRequest = () =>
303
- createRequest({
304
- type: 'object',
305
- properties: {
306
- ...pickProperties(expedition(), ['_id', 'createdAt']),
307
- shop: objectWithShopId().properties.shop,
308
- ...pickProperties(expedition(), [
309
- 'type',
310
- 'code',
311
- 'serviceCode',
312
- 'scheduleCode',
313
- 'date',
314
- 'expectedDeliveryDate',
315
- 'barcodes',
316
- 'packageCount',
317
- 'weight',
318
- 'volume',
319
- 'origin',
320
- 'destination',
321
- 'sender',
322
- 'agency',
323
- 'client',
324
- 'references',
325
- 'packages',
326
- 'notes',
327
- ]),
328
- tags: tags(),
329
- },
330
- required: [
331
- 'shop',
302
+ const createExpeditionWithShop = () => ({
303
+ title: 'create with shop',
304
+ type: 'object',
305
+ properties: {
306
+ ...pickProperties(expedition(), ['_id', 'createdAt']),
307
+ shop: objectWithUuid(),
308
+ ...pickProperties(expedition(), [
332
309
  'type',
333
310
  'code',
334
311
  'serviceCode',
335
312
  'scheduleCode',
336
313
  'date',
337
314
  'expectedDeliveryDate',
315
+ 'barcodes',
338
316
  'packageCount',
339
317
  'weight',
318
+ 'volume',
340
319
  'origin',
341
320
  'destination',
342
321
  'sender',
343
322
  'agency',
344
323
  'client',
345
- ],
346
- additionalProperties: false,
347
- });
324
+ 'references',
325
+ 'packages',
326
+ 'notes',
327
+ ]),
328
+ tags: tags(),
329
+ },
330
+ required: [
331
+ 'shop',
332
+ 'type',
333
+ 'code',
334
+ 'serviceCode',
335
+ 'scheduleCode',
336
+ 'date',
337
+ 'expectedDeliveryDate',
338
+ 'packageCount',
339
+ 'weight',
340
+ 'origin',
341
+ 'destination',
342
+ 'sender',
343
+ 'agency',
344
+ 'client',
345
+ ],
346
+ additionalProperties: false,
347
+ });
348
+
349
+ const createExpeditionWithNetwork = () => ({
350
+ title: 'create with network',
351
+ type: 'object',
352
+ properties: {
353
+ ...pickProperties(expedition(), ['_id', 'createdAt']),
354
+ network: objectWithUuid(),
355
+ ...pickProperties(expedition(), [
356
+ 'type',
357
+ 'code',
358
+ 'serviceCode',
359
+ 'scheduleCode',
360
+ 'date',
361
+ 'expectedDeliveryDate',
362
+ 'barcodes',
363
+ 'packageCount',
364
+ 'weight',
365
+ 'volume',
366
+ 'origin',
367
+ 'destination',
368
+ 'sender',
369
+ 'agency',
370
+ 'client',
371
+ 'references',
372
+ 'packages',
373
+ 'notes',
374
+ ]),
375
+ tags: tags(),
376
+ },
377
+ required: [
378
+ 'network',
379
+ 'type',
380
+ 'code',
381
+ 'serviceCode',
382
+ 'scheduleCode',
383
+ 'date',
384
+ 'expectedDeliveryDate',
385
+ 'packageCount',
386
+ 'weight',
387
+ 'origin',
388
+ 'destination',
389
+ 'sender',
390
+ 'agency',
391
+ 'client',
392
+ ],
393
+ additionalProperties: false,
394
+ });
395
+
396
+ const createExpeditionRequest = () => createRequest({ oneOf: [createExpeditionWithShop(), createExpeditionWithNetwork()] });
348
397
 
349
398
  const createExpeditionResponse = () => createResponse(expedition());
350
399
 
351
400
  const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
352
401
 
402
+ const findByNoShop = () => ({
403
+ title: 'find by no shop',
404
+ type: 'object',
405
+ properties: { shop: { type: 'null' } },
406
+ required: ['shop'],
407
+ additionalProperties: false,
408
+ });
409
+
353
410
  const findByStatus = () => ({
354
411
  title: 'find by status',
355
412
  type: 'object',
@@ -367,6 +424,17 @@ const findByStatus = () => ({
367
424
 
368
425
  const findByShopAndStatus = () => mergeSchemas(findByShop(), findByStatus(), { title: 'find by shop and status' });
369
426
 
427
+ const findByNoShopAndStatus = () => mergeSchemas(findByNoShop(), findByStatus(), { title: 'find by no shop and status' });
428
+
429
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
430
+
431
+ const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
432
+
433
+ const findByNetworkAndNoShop = () => mergeSchemas(findByNetwork(), findByNoShop(), { title: 'find by network and no shop' });
434
+
435
+ const findByNetworkAndNoShopAndStatus = () =>
436
+ mergeSchemas(findByNetworkAndNoShop(), findByStatus(), { title: 'find by network and no shop and status' });
437
+
370
438
  const findByCode = () => ({
371
439
  title: 'find by code',
372
440
  type: 'object',
@@ -377,7 +445,22 @@ const findByCode = () => ({
377
445
  additionalProperties: false,
378
446
  });
379
447
 
380
- const findExpeditionsRequest = () => findRequest({ oneOf: [findById(), findByShop(), findByShopAndStatus(), findByCode()] });
448
+ const findExpeditionsSuperAdminRequest = () =>
449
+ findRequest({
450
+ oneOf: [
451
+ findById(),
452
+ findByNetwork(),
453
+ findByNetworkAndStatus(),
454
+ findByNetworkAndNoShop(),
455
+ findByNetworkAndNoShopAndStatus(),
456
+ findByShop(),
457
+ findByShopAndStatus(),
458
+ findByCode(),
459
+ ],
460
+ });
461
+
462
+ const findExpeditionsNetworkAdminAndShopUserRequest = () =>
463
+ findRequest({ oneOf: [findById(), findByShop(), findByShopAndStatus(), findByNoShop(), findByNoShopAndStatus(), findByCode()] });
381
464
 
382
465
  const findExpeditionsResponse = () => findResponse(expedition());
383
466
 
@@ -466,14 +549,14 @@ const scanExpeditionRequest = () => ({
466
549
  {
467
550
  title: 'barcode',
468
551
  type: 'object',
469
- properties: { barcode: { type: 'string' } },
552
+ properties: { barcode: { type: 'string', trim: true } },
470
553
  required: ['barcode'],
471
554
  additionalProperties: false,
472
555
  },
473
556
  {
474
557
  title: 'QR code',
475
558
  type: 'object',
476
- properties: { qrCode: { type: 'string' } },
559
+ properties: { qrCode: { type: 'string', trim: true } },
477
560
  required: ['qrCode'],
478
561
  additionalProperties: false,
479
562
  },
@@ -619,7 +702,8 @@ module.exports = {
619
702
  objectWithExpeditionId,
620
703
  createExpeditionRequest,
621
704
  createExpeditionResponse,
622
- findExpeditionsRequest,
705
+ findExpeditionsSuperAdminRequest,
706
+ findExpeditionsNetworkAdminAndShopUserRequest,
623
707
  findExpeditionsResponse,
624
708
  updateExpeditionRequest,
625
709
  updateExpeditionResponse,
@@ -17,8 +17,9 @@ const receiveFromDriverEvent = () => ({
17
17
  properties: {
18
18
  _id: expedition().properties._id,
19
19
  receiveFromDriver: mergeSchemas(processedWithDriver(), objectWithShopId(), objectWithNetworkId(), objectWithExpirationDate()),
20
+ expedition: expedition(),
20
21
  },
21
- required: ['_id', 'receiveFromDriver'],
22
+ required: ['_id', 'receiveFromDriver', 'expedition'],
22
23
  additionalProperties: false,
23
24
  });
24
25
 
@@ -33,8 +34,9 @@ const receiveFromCustomerEvent = () => ({
33
34
  objectWithNetworkId(),
34
35
  objectWithExpirationDate(),
35
36
  ),
37
+ expedition: expedition(),
36
38
  },
37
- required: ['_id', 'receiveFromCustomer'],
39
+ required: ['_id', 'receiveFromCustomer', 'expedition'],
38
40
  additionalProperties: false,
39
41
  });
40
42
 
@@ -44,8 +46,9 @@ const giveToCustomerEvent = () => ({
44
46
  properties: {
45
47
  _id: expedition().properties._id,
46
48
  giveToCustomer: mergeSchemas(processedWithCustomerWithPod(), objectWithShopId(), objectWithNetworkId()),
49
+ expedition: expedition(),
47
50
  },
48
- required: ['_id', 'giveToCustomer'],
51
+ required: ['_id', 'giveToCustomer', 'expedition'],
49
52
  additionalProperties: false,
50
53
  });
51
54
 
@@ -55,8 +58,9 @@ const giveToDriverEvent = () => ({
55
58
  properties: {
56
59
  _id: expedition().properties._id,
57
60
  giveToDriver: mergeSchemas(processedWithDriver(), objectWithShopId(), objectWithNetworkId()),
61
+ expedition: expedition(),
58
62
  },
59
- required: ['_id', 'giveToDriver'],
63
+ required: ['_id', 'giveToDriver', 'expedition'],
60
64
  additionalProperties: false,
61
65
  });
62
66
 
@@ -66,8 +70,9 @@ const expirationReminderEvent = () => ({
66
70
  properties: {
67
71
  _id: expedition().properties._id,
68
72
  expirationReminder: mergeSchemas(objectWithExpirationDate(), objectWithShopId(), objectWithNetworkId()),
73
+ expedition: expedition(),
69
74
  },
70
- required: ['_id', 'expirationReminder'],
75
+ required: ['_id', 'expirationReminder', 'expedition'],
71
76
  additionalProperties: false,
72
77
  });
73
78
 
@@ -77,8 +82,9 @@ const expiredEvent = () => ({
77
82
  properties: {
78
83
  _id: expedition().properties._id,
79
84
  expired: mergeSchemas(objectWithExpirationDate(), objectWithShopId(), objectWithNetworkId()),
85
+ expedition: expedition(),
80
86
  },
81
- required: ['_id', 'expired'],
87
+ required: ['_id', 'expired', 'expedition'],
82
88
  additionalProperties: false,
83
89
  });
84
90
 
@@ -93,8 +99,9 @@ const priceEvent = () => ({
93
99
  },
94
100
  required: ['total'],
95
101
  }),
102
+ expedition: expedition(),
96
103
  },
97
- required: ['_id', 'price'],
104
+ required: ['_id', 'price', 'expedition'],
98
105
  additionalProperties: false,
99
106
  });
100
107
 
@@ -0,0 +1,119 @@
1
+ const { uuid, datetime, findRequest, findResponse, mergeSchemas, pickProperties } = require('@gls_spain/common-json-schemas');
2
+ const { network, objectWithNetworkId } = require('./networks');
3
+ const { shop, objectWithShopId } = require('./shops');
4
+ const { expedition, objectWithExpeditionId } = require('./expeditions');
5
+ const { integration } = require('./integrations');
6
+
7
+ const baseHistoricRecord = () => ({
8
+ type: 'object',
9
+ properties: {
10
+ _id: uuid(),
11
+ createdAt: datetime(),
12
+ updatedAt: datetime(),
13
+ action: { type: 'string', enum: ['create', 'update', 'delete'] },
14
+ actionExtras: { type: 'array', items: { type: 'string' }, description: 'additional details about the action, e.g. what was updated' },
15
+ actor: { type: 'string', description: 'the username of the user who made the action' },
16
+ integrations: {
17
+ type: 'object',
18
+ additionalProperties: {
19
+ type: 'object',
20
+ properties: {
21
+ at: datetime(),
22
+ result: { type: 'string', enum: ['completed', 'failed', 'ignored', 'blocked', 'needsReview'] },
23
+ message: { type: 'string' },
24
+ },
25
+ required: ['at', 'result', 'message'],
26
+ description: 'what the integration has done with this record',
27
+ },
28
+ description: 'one property per integration where the property name is the name of the integration',
29
+ },
30
+ },
31
+ required: ['_id', 'createdAt', 'updatedAt', 'action', 'actionExtras', 'actor', 'integrations'],
32
+ additionalProperties: false,
33
+ });
34
+
35
+ const networkHistoricRecord = () =>
36
+ mergeSchemas(baseHistoricRecord(), {
37
+ title: 'network historic record',
38
+ properties: {
39
+ network: network(),
40
+ },
41
+ required: ['network'],
42
+ additionalProperties: false,
43
+ });
44
+
45
+ const shopHistoricRecord = () =>
46
+ mergeSchemas(baseHistoricRecord(), {
47
+ title: 'shop historic record',
48
+ properties: {
49
+ shop: shop(),
50
+ },
51
+ required: ['shop'],
52
+ additionalProperties: false,
53
+ });
54
+
55
+ const expeditionHistoricRecord = () =>
56
+ mergeSchemas(baseHistoricRecord(), {
57
+ title: 'expedition historic record',
58
+ properties: {
59
+ actionExtras: {
60
+ type: 'array',
61
+ items: {
62
+ type: 'string',
63
+ enum: [
64
+ 'receiveFromDriver',
65
+ 'receiveFromCustomer',
66
+ 'giveToDriver',
67
+ 'giveToCustomer',
68
+ 'redirect',
69
+ 'expirationReminder',
70
+ 'expired',
71
+ 'price',
72
+ ],
73
+ },
74
+ },
75
+ expedition: expedition(),
76
+ },
77
+ required: ['expedition'],
78
+ additionalProperties: false,
79
+ });
80
+
81
+ const historicRecord = () => ({ oneOf: [networkHistoricRecord(), shopHistoricRecord(), expeditionHistoricRecord()] });
82
+
83
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
84
+
85
+ const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
86
+
87
+ const findByExpedition = () => mergeSchemas(objectWithExpeditionId(), { title: 'find by expedition' });
88
+
89
+ const findByIntegrationAndResult = () => ({
90
+ title: 'find by integration and result',
91
+ type: 'object',
92
+ properties: {
93
+ integration: {
94
+ type: 'object',
95
+ properties: {
96
+ ...pickProperties(integration(), ['name']),
97
+ ...pickProperties(baseHistoricRecord().properties.integrations.additionalProperties, ['result']),
98
+ },
99
+ required: ['name', 'result'],
100
+ additionalProperties: false,
101
+ },
102
+ },
103
+ required: ['integration'],
104
+ additionalProperties: false,
105
+ });
106
+
107
+ const findHistoricRecordsRequest = () =>
108
+ findRequest({ oneOf: [findByNetwork(), findByShop(), findByExpedition(), findByIntegrationAndResult()] });
109
+
110
+ const findHistoricRecordsResponse = () => findResponse(historicRecord());
111
+
112
+ module.exports = {
113
+ networkHistoricRecord,
114
+ shopHistoricRecord,
115
+ expeditionHistoricRecord,
116
+ historicRecord,
117
+ findHistoricRecordsRequest,
118
+ findHistoricRecordsResponse,
119
+ };
@@ -0,0 +1,28 @@
1
+ const omit = require('lodash/omit');
2
+ const { uuid, datetime, findRequest, findResponse, mergeSchemas } = require('@gls_spain/common-json-schemas');
3
+ const { findAll, findByIds } = require('./common');
4
+
5
+ const integration = () => ({
6
+ title: 'integration',
7
+ type: 'object',
8
+ properties: {
9
+ _id: uuid(),
10
+ createdAt: datetime(),
11
+ updatedAt: datetime(),
12
+ name: { type: 'string' },
13
+ enabled: { type: 'boolean' },
14
+ networks: mergeSchemas(omit(findByIds(), 'title'), { description: 'the integration only applies to these networks' }),
15
+ },
16
+ required: ['_id', 'createdAt', 'updatedAt', 'name', 'enabled', 'networks'],
17
+ additionalProperties: false,
18
+ });
19
+
20
+ const findIntegrationsRequest = () => findRequest({ oneOf: [findAll()] });
21
+
22
+ const findIntegrationsResponse = () => findResponse(integration());
23
+
24
+ module.exports = {
25
+ integration,
26
+ findIntegrationsRequest,
27
+ findIntegrationsResponse,
28
+ };