@gls_spain/gps-common 32.5.0 → 33.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/.idea/workspace.xml +50 -21
- package/CHANGELOG.md +18 -0
- package/errors/InconsistentSalesSettingsError.js +11 -0
- package/errors/InvalidSaleDestinationError.js +11 -0
- package/errors/SaleAlreadyExistsError.js +11 -0
- package/errors/index.js +9 -0
- package/open-api-spec/index.js +451 -305
- package/package.json +1 -1
- package/schemas/definitions/common.js +259 -1
- package/schemas/definitions/defaults.js +88 -2
- package/schemas/definitions/expeditions.js +4 -1
- package/schemas/definitions/gls-spain-integration-events.js +10 -0
- package/schemas/definitions/historic-records.js +5 -2
- package/schemas/definitions/networks.js +15 -3
- package/schemas/definitions/sales.js +163 -0
- package/schemas/index.js +28 -5
- package/schemas/definitions/init.js +0 -50
package/package.json
CHANGED
|
@@ -13,9 +13,266 @@ const { timezones } = require('@gls_spain/ajv-options');
|
|
|
13
13
|
|
|
14
14
|
const date = () => ({ type: 'string', format: 'date' });
|
|
15
15
|
|
|
16
|
+
const country = () => ({
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: [
|
|
19
|
+
'AD',
|
|
20
|
+
'AE',
|
|
21
|
+
'AF',
|
|
22
|
+
'AG',
|
|
23
|
+
'AI',
|
|
24
|
+
'AL',
|
|
25
|
+
'AM',
|
|
26
|
+
'AO',
|
|
27
|
+
'AQ',
|
|
28
|
+
'AR',
|
|
29
|
+
'AS',
|
|
30
|
+
'AT',
|
|
31
|
+
'AU',
|
|
32
|
+
'AW',
|
|
33
|
+
'AX',
|
|
34
|
+
'AZ',
|
|
35
|
+
'BA',
|
|
36
|
+
'BB',
|
|
37
|
+
'BD',
|
|
38
|
+
'BE',
|
|
39
|
+
'BF',
|
|
40
|
+
'BG',
|
|
41
|
+
'BH',
|
|
42
|
+
'BI',
|
|
43
|
+
'BJ',
|
|
44
|
+
'BL',
|
|
45
|
+
'BM',
|
|
46
|
+
'BN',
|
|
47
|
+
'BO',
|
|
48
|
+
'BQ',
|
|
49
|
+
'BR',
|
|
50
|
+
'BS',
|
|
51
|
+
'BT',
|
|
52
|
+
'BV',
|
|
53
|
+
'BW',
|
|
54
|
+
'BY',
|
|
55
|
+
'BZ',
|
|
56
|
+
'CA',
|
|
57
|
+
'CC',
|
|
58
|
+
'CD',
|
|
59
|
+
'CF',
|
|
60
|
+
'CG',
|
|
61
|
+
'CH',
|
|
62
|
+
'CI',
|
|
63
|
+
'CK',
|
|
64
|
+
'CL',
|
|
65
|
+
'CM',
|
|
66
|
+
'CN',
|
|
67
|
+
'CO',
|
|
68
|
+
'CR',
|
|
69
|
+
'CU',
|
|
70
|
+
'CV',
|
|
71
|
+
'CW',
|
|
72
|
+
'CX',
|
|
73
|
+
'CY',
|
|
74
|
+
'CZ',
|
|
75
|
+
'DE',
|
|
76
|
+
'DJ',
|
|
77
|
+
'DK',
|
|
78
|
+
'DM',
|
|
79
|
+
'DO',
|
|
80
|
+
'DZ',
|
|
81
|
+
'EC',
|
|
82
|
+
'EE',
|
|
83
|
+
'EG',
|
|
84
|
+
'EH',
|
|
85
|
+
'ER',
|
|
86
|
+
'ES',
|
|
87
|
+
'ET',
|
|
88
|
+
'FI',
|
|
89
|
+
'FJ',
|
|
90
|
+
'FK',
|
|
91
|
+
'FM',
|
|
92
|
+
'FO',
|
|
93
|
+
'FR',
|
|
94
|
+
'GA',
|
|
95
|
+
'GB',
|
|
96
|
+
'GD',
|
|
97
|
+
'GE',
|
|
98
|
+
'GF',
|
|
99
|
+
'GG',
|
|
100
|
+
'GH',
|
|
101
|
+
'GI',
|
|
102
|
+
'GL',
|
|
103
|
+
'GM',
|
|
104
|
+
'GN',
|
|
105
|
+
'GP',
|
|
106
|
+
'GQ',
|
|
107
|
+
'GR',
|
|
108
|
+
'GS',
|
|
109
|
+
'GT',
|
|
110
|
+
'GU',
|
|
111
|
+
'GW',
|
|
112
|
+
'GY',
|
|
113
|
+
'HK',
|
|
114
|
+
'HM',
|
|
115
|
+
'HN',
|
|
116
|
+
'HR',
|
|
117
|
+
'HT',
|
|
118
|
+
'HU',
|
|
119
|
+
'ID',
|
|
120
|
+
'IE',
|
|
121
|
+
'IL',
|
|
122
|
+
'IM',
|
|
123
|
+
'IN',
|
|
124
|
+
'IO',
|
|
125
|
+
'IQ',
|
|
126
|
+
'IR',
|
|
127
|
+
'IS',
|
|
128
|
+
'IT',
|
|
129
|
+
'JE',
|
|
130
|
+
'JM',
|
|
131
|
+
'JO',
|
|
132
|
+
'JP',
|
|
133
|
+
'KE',
|
|
134
|
+
'KG',
|
|
135
|
+
'KH',
|
|
136
|
+
'KI',
|
|
137
|
+
'KM',
|
|
138
|
+
'KN',
|
|
139
|
+
'KP',
|
|
140
|
+
'KR',
|
|
141
|
+
'KW',
|
|
142
|
+
'KY',
|
|
143
|
+
'KZ',
|
|
144
|
+
'LA',
|
|
145
|
+
'LB',
|
|
146
|
+
'LC',
|
|
147
|
+
'LI',
|
|
148
|
+
'LK',
|
|
149
|
+
'LR',
|
|
150
|
+
'LS',
|
|
151
|
+
'LT',
|
|
152
|
+
'LU',
|
|
153
|
+
'LV',
|
|
154
|
+
'LY',
|
|
155
|
+
'MA',
|
|
156
|
+
'MC',
|
|
157
|
+
'MD',
|
|
158
|
+
'ME',
|
|
159
|
+
'MF',
|
|
160
|
+
'MG',
|
|
161
|
+
'MH',
|
|
162
|
+
'MK',
|
|
163
|
+
'ML',
|
|
164
|
+
'MM',
|
|
165
|
+
'MN',
|
|
166
|
+
'MO',
|
|
167
|
+
'MP',
|
|
168
|
+
'MQ',
|
|
169
|
+
'MR',
|
|
170
|
+
'MS',
|
|
171
|
+
'MT',
|
|
172
|
+
'MU',
|
|
173
|
+
'MV',
|
|
174
|
+
'MW',
|
|
175
|
+
'MX',
|
|
176
|
+
'MY',
|
|
177
|
+
'MZ',
|
|
178
|
+
'NA',
|
|
179
|
+
'NC',
|
|
180
|
+
'NE',
|
|
181
|
+
'NF',
|
|
182
|
+
'NG',
|
|
183
|
+
'NI',
|
|
184
|
+
'NL',
|
|
185
|
+
'NO',
|
|
186
|
+
'NP',
|
|
187
|
+
'NR',
|
|
188
|
+
'NU',
|
|
189
|
+
'NZ',
|
|
190
|
+
'OM',
|
|
191
|
+
'PA',
|
|
192
|
+
'PE',
|
|
193
|
+
'PF',
|
|
194
|
+
'PG',
|
|
195
|
+
'PH',
|
|
196
|
+
'PK',
|
|
197
|
+
'PL',
|
|
198
|
+
'PM',
|
|
199
|
+
'PN',
|
|
200
|
+
'PR',
|
|
201
|
+
'PS',
|
|
202
|
+
'PT',
|
|
203
|
+
'PW',
|
|
204
|
+
'PY',
|
|
205
|
+
'QA',
|
|
206
|
+
'RE',
|
|
207
|
+
'RO',
|
|
208
|
+
'RS',
|
|
209
|
+
'RU',
|
|
210
|
+
'RW',
|
|
211
|
+
'SA',
|
|
212
|
+
'SB',
|
|
213
|
+
'SC',
|
|
214
|
+
'SD',
|
|
215
|
+
'SE',
|
|
216
|
+
'SG',
|
|
217
|
+
'SH',
|
|
218
|
+
'SI',
|
|
219
|
+
'SJ',
|
|
220
|
+
'SK',
|
|
221
|
+
'SL',
|
|
222
|
+
'SM',
|
|
223
|
+
'SN',
|
|
224
|
+
'SO',
|
|
225
|
+
'SR',
|
|
226
|
+
'SS',
|
|
227
|
+
'ST',
|
|
228
|
+
'SV',
|
|
229
|
+
'SX',
|
|
230
|
+
'SY',
|
|
231
|
+
'SZ',
|
|
232
|
+
'TC',
|
|
233
|
+
'TD',
|
|
234
|
+
'TF',
|
|
235
|
+
'TG',
|
|
236
|
+
'TH',
|
|
237
|
+
'TJ',
|
|
238
|
+
'TK',
|
|
239
|
+
'TL',
|
|
240
|
+
'TM',
|
|
241
|
+
'TN',
|
|
242
|
+
'TO',
|
|
243
|
+
'TR',
|
|
244
|
+
'TT',
|
|
245
|
+
'TV',
|
|
246
|
+
'TW',
|
|
247
|
+
'TZ',
|
|
248
|
+
'UA',
|
|
249
|
+
'UG',
|
|
250
|
+
'UM',
|
|
251
|
+
'US',
|
|
252
|
+
'UY',
|
|
253
|
+
'UZ',
|
|
254
|
+
'VA',
|
|
255
|
+
'VC',
|
|
256
|
+
'VE',
|
|
257
|
+
'VG',
|
|
258
|
+
'VI',
|
|
259
|
+
'VN',
|
|
260
|
+
'VU',
|
|
261
|
+
'WF',
|
|
262
|
+
'WS',
|
|
263
|
+
'XK',
|
|
264
|
+
'YE',
|
|
265
|
+
'YT',
|
|
266
|
+
'ZA',
|
|
267
|
+
'ZM',
|
|
268
|
+
'ZW',
|
|
269
|
+
],
|
|
270
|
+
description: 'ISO 3166-1 alpha 2 country code',
|
|
271
|
+
});
|
|
272
|
+
|
|
16
273
|
const address = () =>
|
|
17
274
|
mergeSchemas(genericAddress(), {
|
|
18
|
-
properties: { country:
|
|
275
|
+
properties: { country: country() },
|
|
19
276
|
});
|
|
20
277
|
|
|
21
278
|
const addressWithRequiredLocation = () => mergeSchemas(address(), { required: ['location'] });
|
|
@@ -147,6 +404,7 @@ const findByFiscal = () => ({
|
|
|
147
404
|
|
|
148
405
|
module.exports = {
|
|
149
406
|
date,
|
|
407
|
+
country,
|
|
150
408
|
address,
|
|
151
409
|
addressWithRequiredLocation,
|
|
152
410
|
findAll,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { uuid, datetime, money, updateSelfRequest, updateResponse, pickProperties } = require('@gls_spain/common-json-schemas');
|
|
2
|
+
const { country } = require('./common');
|
|
2
3
|
|
|
3
4
|
const derivationRate = () => ({
|
|
4
5
|
title: 'derivation rate',
|
|
@@ -44,6 +45,88 @@ const expirationSettings = () => ({
|
|
|
44
45
|
additionalProperties: false,
|
|
45
46
|
});
|
|
46
47
|
|
|
48
|
+
const saleSize = () => ({
|
|
49
|
+
type: 'string',
|
|
50
|
+
enum: ['xs', 's', 'm', 'l', 'xl'],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const saleZone = () => ({
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
name: { type: 'string', trim: true },
|
|
57
|
+
prices: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
xs: money(),
|
|
61
|
+
s: money(),
|
|
62
|
+
m: money(),
|
|
63
|
+
l: money(),
|
|
64
|
+
xl: money(),
|
|
65
|
+
},
|
|
66
|
+
required: ['xs', 's', 'm', 'l', 'xl'],
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['name', 'prices'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const salePostalCodeZone = () => ({
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
prefix: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'include only the postal codes that begin with this prefix',
|
|
80
|
+
},
|
|
81
|
+
zone: {
|
|
82
|
+
oneOf: [
|
|
83
|
+
{
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'name of the zone for this country and postal codes, must exist in the zones array',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: 'null',
|
|
89
|
+
description: 'set to null to prevent sales to this country and postal codes',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
required: ['prefix', 'zone'],
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const saleCountry = () => ({
|
|
99
|
+
type: 'object',
|
|
100
|
+
properties: {
|
|
101
|
+
country: country(),
|
|
102
|
+
postalCodesZones: { type: 'array', items: salePostalCodeZone(), uniqueItems: true },
|
|
103
|
+
defaultZone: {
|
|
104
|
+
oneOf: [
|
|
105
|
+
{
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'name of the default zone for this country, must exist in the zones array',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: 'null',
|
|
111
|
+
description: 'set to null to prevent sales to this country by default',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
required: ['country', 'postalCodesZones', 'defaultZone'],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const salesSettings = () => ({
|
|
120
|
+
title: 'sales settings',
|
|
121
|
+
type: 'object',
|
|
122
|
+
properties: {
|
|
123
|
+
zones: { type: 'array', items: saleZone(), uniqueItems: true, minItems: 1 },
|
|
124
|
+
countries: { type: 'array', items: saleCountry(), uniqueItems: true, minItems: 1 },
|
|
125
|
+
},
|
|
126
|
+
required: ['zones', 'countries'],
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
});
|
|
129
|
+
|
|
47
130
|
const defaults = () => ({
|
|
48
131
|
title: 'defaults',
|
|
49
132
|
type: 'object',
|
|
@@ -54,8 +137,9 @@ const defaults = () => ({
|
|
|
54
137
|
deletable: { type: 'boolean' },
|
|
55
138
|
derivationSettings: derivationSettings(),
|
|
56
139
|
expirationSettings: expirationSettings(),
|
|
140
|
+
salesSettings: salesSettings(),
|
|
57
141
|
},
|
|
58
|
-
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'derivationSettings', 'expirationSettings'],
|
|
142
|
+
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'derivationSettings', 'expirationSettings', 'salesSettings'],
|
|
59
143
|
additionalProperties: false,
|
|
60
144
|
});
|
|
61
145
|
|
|
@@ -71,7 +155,7 @@ const getDefaultsResponse = () => ({
|
|
|
71
155
|
const updateDefaultsRequest = () =>
|
|
72
156
|
updateSelfRequest({
|
|
73
157
|
type: 'object',
|
|
74
|
-
properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
|
|
158
|
+
properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings', 'salesSettings']) },
|
|
75
159
|
minProperties: 1,
|
|
76
160
|
additionalProperties: false,
|
|
77
161
|
});
|
|
@@ -81,6 +165,8 @@ const updateDefaultsResponse = () => updateResponse(defaults());
|
|
|
81
165
|
module.exports = {
|
|
82
166
|
derivationSettings,
|
|
83
167
|
expirationSettings,
|
|
168
|
+
saleSize,
|
|
169
|
+
salesSettings,
|
|
84
170
|
defaults,
|
|
85
171
|
getDefaultsResponse,
|
|
86
172
|
updateDefaultsRequest,
|
|
@@ -136,7 +136,7 @@ const expedition = () => ({
|
|
|
136
136
|
additionalProperties: false,
|
|
137
137
|
description: 'not available for incoming expeditions that are not assigned to a shop until reception',
|
|
138
138
|
},
|
|
139
|
-
type: { type: 'string', enum: ['delivery', 'pickup'
|
|
139
|
+
type: { type: 'string', enum: ['delivery', 'pickup'] },
|
|
140
140
|
status: {
|
|
141
141
|
type: 'object',
|
|
142
142
|
properties: {
|
|
@@ -188,6 +188,7 @@ const expedition = () => ({
|
|
|
188
188
|
additionalProperties: false,
|
|
189
189
|
description: 'only available for deliveries and pickups after reception at the shop',
|
|
190
190
|
},
|
|
191
|
+
sale: mergeSchemas(objectWithUuid(), { description: 'associated sale, only for pickups created because of a sale' }),
|
|
191
192
|
barcodes: { type: 'array', items: { type: 'string', trim: true } },
|
|
192
193
|
packageCount: { type: 'integer' },
|
|
193
194
|
weight: { type: 'number' },
|
|
@@ -300,6 +301,7 @@ const createExpeditionWithShop = () => ({
|
|
|
300
301
|
'scheduleCode',
|
|
301
302
|
'date',
|
|
302
303
|
'expectedDeliveryDate',
|
|
304
|
+
'sale',
|
|
303
305
|
'barcodes',
|
|
304
306
|
'packageCount',
|
|
305
307
|
'weight',
|
|
@@ -346,6 +348,7 @@ const createExpeditionWithNetwork = () => ({
|
|
|
346
348
|
'scheduleCode',
|
|
347
349
|
'date',
|
|
348
350
|
'expectedDeliveryDate',
|
|
351
|
+
'sale',
|
|
349
352
|
'barcodes',
|
|
350
353
|
'packageCount',
|
|
351
354
|
'weight',
|
|
@@ -3,6 +3,7 @@ const { date } = require('./common');
|
|
|
3
3
|
const { expedition, processedWithDriver, processedWithCustomerWithPod } = require('./expeditions');
|
|
4
4
|
const { shop, objectWithShopId } = require('./shops');
|
|
5
5
|
const { network, objectWithNetworkId } = require('./networks');
|
|
6
|
+
const { sale } = require('./sales');
|
|
6
7
|
|
|
7
8
|
const objectWithExpirationDate = () => ({
|
|
8
9
|
type: 'object',
|
|
@@ -116,6 +117,14 @@ const upsertNetworkEvent = () => ({
|
|
|
116
117
|
additionalProperties: false,
|
|
117
118
|
});
|
|
118
119
|
|
|
120
|
+
const upsertSaleEvent = () => ({
|
|
121
|
+
title: 'upsert sale',
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: { sale: sale() },
|
|
124
|
+
required: ['sale'],
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
});
|
|
127
|
+
|
|
119
128
|
module.exports = {
|
|
120
129
|
receiveFromDriverEvent,
|
|
121
130
|
receiveFromCustomerEvent,
|
|
@@ -126,4 +135,5 @@ module.exports = {
|
|
|
126
135
|
priceEvent,
|
|
127
136
|
upsertShopEvent,
|
|
128
137
|
upsertNetworkEvent,
|
|
138
|
+
upsertSaleEvent,
|
|
129
139
|
};
|
|
@@ -7,6 +7,7 @@ const { representative } = require('./representatives');
|
|
|
7
7
|
const { shop } = require('./shops');
|
|
8
8
|
const { expedition } = require('./expeditions');
|
|
9
9
|
const { integration } = require('./integrations');
|
|
10
|
+
const { sale } = require('./sales');
|
|
10
11
|
|
|
11
12
|
const historicRecord = () => ({
|
|
12
13
|
title: 'historicRecord',
|
|
@@ -18,9 +19,11 @@ const historicRecord = () => ({
|
|
|
18
19
|
deletable: { type: 'boolean' },
|
|
19
20
|
type: {
|
|
20
21
|
type: 'string',
|
|
21
|
-
enum: ['defaults', 'superAdmin', 'network', 'networkAdmin', 'zone', 'representative', 'shop', 'shopUser', 'expedition'],
|
|
22
|
+
enum: ['defaults', 'superAdmin', 'network', 'networkAdmin', 'zone', 'representative', 'shop', 'shopUser', 'expedition', 'sale'],
|
|
23
|
+
},
|
|
24
|
+
document: {
|
|
25
|
+
oneOf: [defaults(), superAdmin(), network(), networkAdmin(), zone(), representative(), shop(), shopUser(), expedition(), sale()],
|
|
22
26
|
},
|
|
23
|
-
document: { oneOf: [defaults(), superAdmin(), network(), networkAdmin(), zone(), representative(), shop(), shopUser(), expedition()] },
|
|
24
27
|
action: { type: 'string', enum: ['create', 'update', 'delete'] },
|
|
25
28
|
actionKeys: {
|
|
26
29
|
type: 'array',
|
|
@@ -38,8 +38,17 @@ const network = () => ({
|
|
|
38
38
|
fiscal: fiscal(),
|
|
39
39
|
derivationSettings: derivationSettings(),
|
|
40
40
|
expirationSettings: expirationSettings(),
|
|
41
|
+
salesSettings: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
networkPercentage: { type: 'integer', minimum: 0 },
|
|
45
|
+
shopPercentage: { type: 'integer', minimum: 0 },
|
|
46
|
+
},
|
|
47
|
+
required: ['networkPercentage', 'shopPercentage'],
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
},
|
|
41
50
|
},
|
|
42
|
-
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'readonly', 'defaults', 'name', 'contacts'],
|
|
51
|
+
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'readonly', 'defaults', 'name', 'contacts', 'salesSettings'],
|
|
43
52
|
additionalProperties: false,
|
|
44
53
|
});
|
|
45
54
|
|
|
@@ -63,9 +72,10 @@ const createNetworkRequest = () =>
|
|
|
63
72
|
'fiscal',
|
|
64
73
|
'derivationSettings',
|
|
65
74
|
'expirationSettings',
|
|
75
|
+
'salesSettings',
|
|
66
76
|
]),
|
|
67
77
|
},
|
|
68
|
-
required: ['name'],
|
|
78
|
+
required: ['name', 'salesSettings'],
|
|
69
79
|
additionalProperties: false,
|
|
70
80
|
});
|
|
71
81
|
|
|
@@ -85,7 +95,9 @@ const findNetworksResponse = () => findResponse(network());
|
|
|
85
95
|
const updateNetworkRequest = () =>
|
|
86
96
|
updateRequest(findById(), {
|
|
87
97
|
type: 'object',
|
|
88
|
-
properties: {
|
|
98
|
+
properties: {
|
|
99
|
+
...pickProperties(network(), ['name', 'contacts', 'salesSettings'], ['fiscal', 'derivationSettings', 'expirationSettings']),
|
|
100
|
+
},
|
|
89
101
|
minProperties: 1,
|
|
90
102
|
additionalProperties: false,
|
|
91
103
|
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const {
|
|
2
|
+
uuid,
|
|
3
|
+
datetime,
|
|
4
|
+
email,
|
|
5
|
+
phone,
|
|
6
|
+
money,
|
|
7
|
+
createRequest,
|
|
8
|
+
createResponse,
|
|
9
|
+
findRequest,
|
|
10
|
+
findResponse,
|
|
11
|
+
mergeSchemas,
|
|
12
|
+
pickProperties,
|
|
13
|
+
} = require('@gls_spain/common-json-schemas');
|
|
14
|
+
const { country, findAll, findById } = require('./common');
|
|
15
|
+
const { address } = require('./common');
|
|
16
|
+
const { saleSize, salesSettings } = require('./defaults');
|
|
17
|
+
const { network, objectWithNetworkId } = require('./networks');
|
|
18
|
+
const { shop, objectWithShopId } = require('./shops');
|
|
19
|
+
|
|
20
|
+
const sale = () => ({
|
|
21
|
+
title: 'sale',
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
_id: uuid(),
|
|
25
|
+
createdAt: datetime(),
|
|
26
|
+
updatedAt: datetime(),
|
|
27
|
+
deletable: { type: 'boolean' },
|
|
28
|
+
network: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: { ...pickProperties(network(), ['_id', 'name']) },
|
|
31
|
+
required: ['_id', 'name'],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
shop: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: { ...pickProperties(shop(), ['_id', 'name']) },
|
|
37
|
+
required: ['_id', 'name'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
status: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
code: { type: 'string', enum: ['pending', 'paid', 'failed'] },
|
|
44
|
+
},
|
|
45
|
+
required: ['code'],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
size: saleSize(),
|
|
49
|
+
price: money(),
|
|
50
|
+
settings: mergeSchemas(salesSettings(), network().properties.salesSettings, {
|
|
51
|
+
description: 'a copy of both the defaults sale settings and the network sale settings as they were when the sale was created',
|
|
52
|
+
}),
|
|
53
|
+
destination: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
name: { type: 'string', trim: true },
|
|
57
|
+
address: address(),
|
|
58
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
59
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
60
|
+
notes: { type: 'string', trim: true },
|
|
61
|
+
},
|
|
62
|
+
required: ['name', 'address', 'emails', 'phones'],
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
},
|
|
65
|
+
sender: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
name: { type: 'string', trim: true },
|
|
69
|
+
nif: { type: 'string', trim: true },
|
|
70
|
+
address: address(),
|
|
71
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
72
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
73
|
+
fiscal: {
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: {
|
|
76
|
+
name: { type: 'string', trim: true },
|
|
77
|
+
nif: { type: 'string', trim: true },
|
|
78
|
+
address: address(),
|
|
79
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
80
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
81
|
+
},
|
|
82
|
+
required: ['name', 'nif', 'address', 'emails', 'phones'],
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
},
|
|
85
|
+
notes: { type: 'string', trim: true },
|
|
86
|
+
reference: { type: 'string', trim: true },
|
|
87
|
+
},
|
|
88
|
+
required: ['name', 'nif', 'address', 'emails', 'phones', 'fiscal'],
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
required: [
|
|
93
|
+
'_id',
|
|
94
|
+
'createdAt',
|
|
95
|
+
'updatedAt',
|
|
96
|
+
'deletable',
|
|
97
|
+
'network',
|
|
98
|
+
'shop',
|
|
99
|
+
'status',
|
|
100
|
+
'size',
|
|
101
|
+
'price',
|
|
102
|
+
'settings',
|
|
103
|
+
'destination',
|
|
104
|
+
'sender',
|
|
105
|
+
],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const createSaleRequest = () =>
|
|
110
|
+
createRequest({
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
...pickProperties(sale(), ['_id', 'createdAt', 'size', 'destination', 'sender']),
|
|
114
|
+
},
|
|
115
|
+
required: ['shop', 'size', 'destination', 'sender'],
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const createSaleResponse = () => createResponse(sale());
|
|
120
|
+
|
|
121
|
+
const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
|
|
122
|
+
|
|
123
|
+
const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
|
|
124
|
+
|
|
125
|
+
const findSalesSuperAdminRequest = () => findRequest({ oneOf: [findAll(), findByNetwork(), findByShop(), findById()] });
|
|
126
|
+
|
|
127
|
+
const findSalesNetworkAdminRequest = () => findRequest({ oneOf: [findAll(), findByShop(), findById()] });
|
|
128
|
+
|
|
129
|
+
const findSalesShopUserRequest = () => findRequest({ oneOf: [findAll(), findById()] });
|
|
130
|
+
|
|
131
|
+
const findSalesResponse = () => findResponse(sale());
|
|
132
|
+
|
|
133
|
+
const checkSalePriceRequest = () => ({
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
size: saleSize(),
|
|
137
|
+
country: country(),
|
|
138
|
+
postalCode: { type: 'string', trim: true },
|
|
139
|
+
},
|
|
140
|
+
required: ['size', 'country', 'postalCode'],
|
|
141
|
+
additionalProperties: false,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const checkSalePriceResponse = () => ({
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: {
|
|
147
|
+
price: money(),
|
|
148
|
+
},
|
|
149
|
+
required: ['price'],
|
|
150
|
+
additionalProperties: false,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
module.exports = {
|
|
154
|
+
sale,
|
|
155
|
+
createSaleRequest,
|
|
156
|
+
createSaleResponse,
|
|
157
|
+
findSalesSuperAdminRequest,
|
|
158
|
+
findSalesNetworkAdminRequest,
|
|
159
|
+
findSalesShopUserRequest,
|
|
160
|
+
findSalesResponse,
|
|
161
|
+
checkSalePriceRequest,
|
|
162
|
+
checkSalePriceResponse,
|
|
163
|
+
};
|