@gls_spain/gps-common 32.5.0 → 33.0.1
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 +46 -22
- package/CHANGELOG.md +25 -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 +461 -305
- package/package.json +1 -1
- package/schemas/definitions/common.js +259 -1
- package/schemas/definitions/defaults.js +54 -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/open-api-spec/index.js
CHANGED
|
@@ -38,9 +38,11 @@ const {
|
|
|
38
38
|
ZoneDoesNotExistError,
|
|
39
39
|
ZoneAlreadyExistsError,
|
|
40
40
|
ZoneCannotBeDeletedError,
|
|
41
|
+
SaleAlreadyExistsError,
|
|
42
|
+
InconsistentSalesSettingsError,
|
|
43
|
+
InvalidSaleDestinationError,
|
|
41
44
|
} = require('../errors');
|
|
42
45
|
const { timezoneNames } = require('../schemas/definitions/common');
|
|
43
|
-
const { initRequest, initResponse } = require('../schemas/definitions/init');
|
|
44
46
|
const { loginResponse } = require('../schemas/definitions/login');
|
|
45
47
|
const { logoutResponse } = require('../schemas/definitions/logout');
|
|
46
48
|
const { becomeRequest } = require('../schemas/definitions/become');
|
|
@@ -135,6 +137,7 @@ const {
|
|
|
135
137
|
priceEvent,
|
|
136
138
|
upsertShopEvent,
|
|
137
139
|
upsertNetworkEvent,
|
|
140
|
+
upsertSaleEvent,
|
|
138
141
|
} = require('../schemas/definitions/gls-spain-integration-events');
|
|
139
142
|
const {
|
|
140
143
|
representative,
|
|
@@ -164,6 +167,17 @@ const {
|
|
|
164
167
|
} = require('../schemas/definitions/zones');
|
|
165
168
|
const { integration, findIntegrationsRequest, findIntegrationsResponse } = require('../schemas/definitions/integrations');
|
|
166
169
|
const { historicRecord, findHistoricRecordsRequest, findHistoricRecordsResponse } = require('../schemas/definitions/historic-records');
|
|
170
|
+
const {
|
|
171
|
+
sale,
|
|
172
|
+
createSaleRequest,
|
|
173
|
+
createSaleResponse,
|
|
174
|
+
findSalesSuperAdminRequest,
|
|
175
|
+
findSalesNetworkAdminRequest,
|
|
176
|
+
findSalesShopUserRequest,
|
|
177
|
+
findSalesResponse,
|
|
178
|
+
checkSalePriceRequest,
|
|
179
|
+
checkSalePriceResponse,
|
|
180
|
+
} = require('../schemas/definitions/sales');
|
|
167
181
|
|
|
168
182
|
const openApiSpec = { openapi: '3.0.2' };
|
|
169
183
|
|
|
@@ -200,36 +214,20 @@ openApiSpec.servers = [
|
|
|
200
214
|
openApiSpec['x-tagGroups'] = [
|
|
201
215
|
{
|
|
202
216
|
name: '',
|
|
203
|
-
tags: ['Introduction', 'Errors', 'Data formats'],
|
|
217
|
+
tags: ['Introduction', 'Errors', 'Deleting', 'Data formats', 'Historic records introduction'],
|
|
204
218
|
},
|
|
205
219
|
{
|
|
206
|
-
name: '
|
|
220
|
+
name: 'BACKGROUND PROCESSES',
|
|
207
221
|
tags: [
|
|
208
|
-
'
|
|
209
|
-
'
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
'
|
|
214
|
-
'
|
|
215
|
-
'Shop',
|
|
216
|
-
'Shop user',
|
|
217
|
-
'Expedition',
|
|
218
|
-
'Pod',
|
|
222
|
+
'Types of background processes',
|
|
223
|
+
'Eventual consistency',
|
|
224
|
+
'Expeditions expiration',
|
|
225
|
+
'GLS Spain integration',
|
|
226
|
+
'GLS International integration',
|
|
227
|
+
'GLS SMS integration',
|
|
228
|
+
'Ingenico integration',
|
|
219
229
|
],
|
|
220
230
|
},
|
|
221
|
-
{
|
|
222
|
-
name: 'HISTORIC RECORDS',
|
|
223
|
-
tags: ['Historic records introduction'],
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: 'BACKGROUND WORK',
|
|
227
|
-
tags: ['Background work', 'Eventual consistency', 'Expeditions expiration'],
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
name: 'INTEGRATIONS',
|
|
231
|
-
tags: ['Integrations introduction', 'GLS Spain'],
|
|
232
|
-
},
|
|
233
231
|
{
|
|
234
232
|
name: 'ENDPOINTS',
|
|
235
233
|
tags: [
|
|
@@ -245,6 +243,7 @@ openApiSpec['x-tagGroups'] = [
|
|
|
245
243
|
'Shop users',
|
|
246
244
|
'Expeditions',
|
|
247
245
|
'Pods',
|
|
246
|
+
'Sales',
|
|
248
247
|
'Historic records',
|
|
249
248
|
'Integrations',
|
|
250
249
|
],
|
|
@@ -257,29 +256,27 @@ openApiSpec.tags = [
|
|
|
257
256
|
description: `
|
|
258
257
|
This is the API for managing GLS parcel shops, which are establishments that can store packages for the customers to pick up.
|
|
259
258
|
|
|
260
|
-
Parcel shops are grouped by networks, which are the companies or associations that have a deal with GLS to use their
|
|
261
|
-
|
|
259
|
+
Parcel shops are grouped by networks, which are the companies or associations that have a deal with GLS to use their establishments as
|
|
260
|
+
parcel shops.
|
|
262
261
|
|
|
263
262
|
The API can be used by 3 kinds of users:
|
|
264
263
|
|
|
265
264
|
- Super admins: these are the GLS staff that manage the entire API. They can:
|
|
266
265
|
|
|
267
266
|
- Manage all kinds of users, including other super admins.
|
|
268
|
-
- Manage networks.
|
|
269
|
-
- Manage shops from any network.
|
|
267
|
+
- Manage networks, zones, representatives, historic records and integrations.
|
|
268
|
+
- Manage shops, expeditions and sales from any network.
|
|
270
269
|
|
|
271
270
|
- Network admins: these are the managers of a single network. They can:
|
|
272
271
|
|
|
273
|
-
- Manage shops from their network.
|
|
272
|
+
- Manage shops, expeditions and sales from their network.
|
|
274
273
|
- Manage their shop users.
|
|
275
274
|
|
|
276
275
|
- Shop users: these are the staff that work at the parcel shops. They can:
|
|
277
276
|
|
|
278
277
|
- View the shop inventory.
|
|
279
|
-
- Receive
|
|
280
|
-
-
|
|
281
|
-
- Receive returns from customers.
|
|
282
|
-
- Give returns to GLS drivers.
|
|
278
|
+
- Receive and deliver packages.
|
|
279
|
+
- Sell delivery services to people.
|
|
283
280
|
- etc...
|
|
284
281
|
|
|
285
282
|
Every endpoint of this documentation has a caption before its name indicating who can use it: **[S]** for super admins,
|
|
@@ -303,6 +300,16 @@ An endpoint can return more than one error with the same HTTP status, e.g.:
|
|
|
303
300
|
- \`500 UserCannotBeDeletedError\`.
|
|
304
301
|
|
|
305
302
|
You will need to look at the name to differentiate them.`,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'Deleting',
|
|
306
|
+
description: `
|
|
307
|
+
All resources have a \`deletable\` field that indicates if they can be deleted. It starts as \`true\` when the resource is created and it
|
|
308
|
+
changes to \`false\` when it is referenced as a dependency by another resource. Once changed it never changes back to \`true\`, even if the
|
|
309
|
+
dependent is deleted.
|
|
310
|
+
|
|
311
|
+
Trying to delete a non deletable resource will throw a deletion error, for example \`500 ShopCannotBeDeletedError\` when it is a shop.
|
|
312
|
+
`,
|
|
306
313
|
},
|
|
307
314
|
{
|
|
308
315
|
name: 'Data formats',
|
|
@@ -310,7 +317,7 @@ You will need to look at the name to differentiate them.`,
|
|
|
310
317
|
The API follows the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)
|
|
311
318
|
and the [JSON Schema draft 7 standard](https://json-schema.org/understanding-json-schema/index.html) for data types.
|
|
312
319
|
|
|
313
|
-
There are
|
|
320
|
+
There are three string formats that require special consideration: \`uuid\`, \`date-time\` and \`timezone\`.
|
|
314
321
|
|
|
315
322
|
#### Strings with uuid format
|
|
316
323
|
|
|
@@ -342,167 +349,39 @@ The full list of allowed timezone names is:
|
|
|
342
349
|
|
|
343
350
|
<SchemaDefinition schemaRef="#/components/schemas/timezoneNames" />
|
|
344
351
|
`,
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: 'Defaults',
|
|
348
|
-
description: `
|
|
349
|
-
The API has some default settings for networks and shops that do not specify their own, like the rate prices for deliveries and pickups,
|
|
350
|
-
the maximum number of days that an expedition can be in a shop before returning it, etc.
|
|
351
|
-
|
|
352
|
-
Super administrators can view and update this default settings using the [config](#tag/Config) endpoints.
|
|
353
|
-
|
|
354
|
-
<SchemaDefinition schemaRef="#/components/schemas/defaults" />`,
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
name: 'Counters',
|
|
358
|
-
description: `
|
|
359
|
-
Some of the API resources have fields that are auto incremental values. The API keeps a counter for each of these fields to know what the
|
|
360
|
-
next value to use is.
|
|
361
|
-
|
|
362
|
-
Super administrators can view the last values used for each auto incremental field using the [config](#tag/Config) endpoints.
|
|
363
|
-
|
|
364
|
-
<SchemaDefinition schemaRef="#/components/schemas/counters" />`,
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
name: 'Super admin',
|
|
368
|
-
description: `
|
|
369
|
-
Super administrators can manage all the resources of the API.
|
|
370
|
-
|
|
371
|
-
An initial super administrator is created when the API is deployed (see [config](#tag/Config)) and then that super administrator
|
|
372
|
-
can create additional super administrators using the [super admins](#tag/Super-admins) endpoints.
|
|
373
|
-
|
|
374
|
-
<SchemaDefinition schemaRef="#/components/schemas/superAdmin" />`,
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
name: 'Network',
|
|
378
|
-
description: `
|
|
379
|
-
Networks represent the providers of parcel shops, e.g. the companies or associations that have a deal with GLS to use
|
|
380
|
-
their establishments as parcel shops. Every parcel shop belongs to a single network.
|
|
381
|
-
|
|
382
|
-
Super administrators can manage networks using the [networks](#tag/Networks) endpoints.
|
|
383
|
-
|
|
384
|
-
<SchemaDefinition schemaRef="#/components/schemas/network" />`,
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
name: 'Network admin',
|
|
388
|
-
description: `
|
|
389
|
-
Network administrators are associated with a single network and they can view the parcel shops that belong to their network.
|
|
390
|
-
|
|
391
|
-
Super administrators can manage network administrators using the [network admins](#tag/Network-admins) endpoints.
|
|
392
|
-
|
|
393
|
-
<SchemaDefinition schemaRef="#/components/schemas/networkAdmin" />`,
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
name: 'Zone',
|
|
397
|
-
description: `
|
|
398
|
-
Zones are geographic areas that define the commissions that the sales representatives earn for their work on the shops in those areas.
|
|
399
|
-
|
|
400
|
-
Super administrators can create and manage zones using the [zones](#tag/Zones) endpoints, and then associate them to parcel shops and sales
|
|
401
|
-
representatives on creation or update.
|
|
402
|
-
|
|
403
|
-
<SchemaDefinition schemaRef="#/components/schemas/zone" />`,
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
name: 'Sales representative',
|
|
407
|
-
description: `
|
|
408
|
-
Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop
|
|
409
|
-
in the API has two representatives associated to it: the one that made the deal to open the shop and the one that is currently
|
|
410
|
-
managing it.
|
|
411
|
-
|
|
412
|
-
Super administrators can create and manage sales representatives using the [sales representatives](#tag/Sales-representatives)
|
|
413
|
-
endpoints, and then associate them to parcel shops on creation or update.
|
|
414
|
-
|
|
415
|
-
<SchemaDefinition schemaRef="#/components/schemas/representative" />`,
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
name: 'Shop',
|
|
419
|
-
description: `
|
|
420
|
-
Parcel shops are the establishments that GLS and the customers can use to deliver and pickup expeditions instead of doing
|
|
421
|
-
it at the customers home.
|
|
422
|
-
|
|
423
|
-
Every parcel shop is associated to a network, and it must have at least one shop user associated to it for the parcel
|
|
424
|
-
shop to function.
|
|
425
|
-
|
|
426
|
-
Super administrators can manage shops from any network and network administrators can view shops from their own network
|
|
427
|
-
using the [shops](#tag/Shops) endpoints.
|
|
428
|
-
|
|
429
|
-
<SchemaDefinition schemaRef="#/components/schemas/shop" />`,
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
name: 'Shop user',
|
|
433
|
-
description: `
|
|
434
|
-
Shop users are associated with a single shop and they have limited capabilities to manage the shop and its expeditions,
|
|
435
|
-
e.g. they can edit some of the shop properties or receive and deliver expeditions, but not edit anything else about them.
|
|
436
|
-
|
|
437
|
-
Super administrators can manage shop users from any network and network administrators can view shop users from their
|
|
438
|
-
own network using the [shop users](#tag/Shop-users) endpoints.
|
|
439
|
-
|
|
440
|
-
<SchemaDefinition schemaRef="#/components/schemas/shopUser" />`,
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
name: 'Expedition',
|
|
444
|
-
description: `
|
|
445
|
-
Expeditions are the packages that are delivered and picked up at parcel shops.
|
|
446
|
-
|
|
447
|
-
Super administrators can manage expeditions using the [expeditions](#tag/Expeditions) endpoints. Shop users can also use
|
|
448
|
-
some of those endpoints to receive and give expeditions from and to GLS and customers.
|
|
449
|
-
|
|
450
|
-
<SchemaDefinition schemaRef="#/components/schemas/expedition" />`,
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
name: 'Pod',
|
|
454
|
-
description: `
|
|
455
|
-
Expeditions that have been picked up by or delivered to a customer have a POD (Proof Of Delivery) associated to them that contains the
|
|
456
|
-
signature of the customer.
|
|
457
|
-
|
|
458
|
-
Pods are created automatically by the API when an expedition is picked up by or delivered to a customer.
|
|
459
|
-
|
|
460
|
-
Super administrators, network administrators and shop users can use the [pods](#tag/Pods) endpoints to find the pods of the
|
|
461
|
-
expeditions they have access to.
|
|
462
|
-
|
|
463
|
-
<SchemaDefinition schemaRef="#/components/schemas/pod" />`,
|
|
464
352
|
},
|
|
465
353
|
{
|
|
466
354
|
name: 'Historic records introduction',
|
|
467
355
|
'x-displayName': 'Historic records',
|
|
468
356
|
description: `
|
|
469
|
-
Every time the API creates, updates or deletes a resource it
|
|
470
|
-
the action, the time it occurred and the user that made it.
|
|
471
|
-
|
|
472
|
-
The only exception are \`pods\` which have no records because they are created when their expeditions are delivered and they are never
|
|
473
|
-
updated. They are also never deleted because they need to remain accessible via the historic records of expeditions.
|
|
357
|
+
Every time the API creates, updates or deletes a resource it creates a historic record that stores the action taken (create, update, or
|
|
358
|
+
delete), the full document as it was after the action, the time it occurred and the user that made it.
|
|
474
359
|
|
|
475
360
|
These historic records serve two purposes:
|
|
476
361
|
|
|
477
|
-
- They allow to track the full history of a
|
|
478
|
-
- They are the basis for the [
|
|
479
|
-
|
|
480
|
-
The \`actionKeys\` lists the paths of the updated fields for an \`update\` action. The depth of the paths may vary:
|
|
362
|
+
- They allow to track the full history of a resource.
|
|
363
|
+
- They are the basis for the [background processes](#tag/Types-of-background-processes) of the API.
|
|
481
364
|
|
|
482
|
-
|
|
483
|
-
- Some updated are more specific, for example delivering an expedition is \`status.code\` and \`status.givenTo\`.
|
|
484
|
-
|
|
485
|
-
The \`integrations\` field is where each integration stores what it did with it. Its properties are the names of the integrations and
|
|
486
|
-
their values the result of that integration for that record.
|
|
487
|
-
|
|
488
|
-
Super administrators can search the historic records using the [historic records](#tag/Historic-records) endpoints.
|
|
489
|
-
|
|
490
|
-
<SchemaDefinition schemaRef="#/components/schemas/historicRecord" />`,
|
|
365
|
+
See the [historic records](#tag/Historic-records) endpoints for more information.`,
|
|
491
366
|
},
|
|
492
367
|
{
|
|
493
|
-
name: '
|
|
368
|
+
name: 'Types of background processes',
|
|
494
369
|
description: `
|
|
495
|
-
|
|
496
|
-
|
|
370
|
+
The API runs two types of processes in the background:
|
|
371
|
+
|
|
372
|
+
- Some processes execute an action at regular time intervals.
|
|
373
|
+
- Some processes execute an action every time a new historic record is created.
|
|
374
|
+
|
|
375
|
+
This section explains what each kind of background process does.`,
|
|
497
376
|
},
|
|
498
377
|
{
|
|
499
378
|
name: 'Eventual consistency',
|
|
500
379
|
description: `
|
|
501
|
-
|
|
502
|
-
|
|
380
|
+
When one resource depends on another it stores the \`_id\` of its dependency, for example each shop stores the network it belongs to in
|
|
381
|
+
its \`network._id\` field.
|
|
503
382
|
|
|
504
|
-
|
|
505
|
-
|
|
383
|
+
When a resource also needs other fields of its dependency very often it makes sense to store them with the \`_id\`, for example each shop
|
|
384
|
+
also stores the name of its network in its \`network.name\` field.
|
|
506
385
|
|
|
507
386
|
This is called denormalization and it saves a lot of queries for the full dependency each time these fields are needed. The downside is
|
|
508
387
|
that an update in the dependency requires updating the dependents too. There are two strategies to do this:
|
|
@@ -512,64 +391,53 @@ are thousands or millions of dependents.
|
|
|
512
391
|
- **Eventual consistency**: only the dependency is updated immediately, and the dependents are updated later in the background. The update
|
|
513
392
|
endpoint returns very fast but for a few seconds the dependents are outdated.
|
|
514
393
|
|
|
515
|
-
|
|
516
|
-
|
|
394
|
+
The API runs an eventual consistency background process that watches the historic records. When a record updates the appropriate field in
|
|
395
|
+
a dependency, the background process updates also all the relevant dependents.`,
|
|
517
396
|
},
|
|
518
397
|
{
|
|
519
398
|
name: 'Expeditions expiration',
|
|
520
399
|
description: `
|
|
521
|
-
Delivery expeditions can only be in a shop for a certain amount of time before GLS returns them to the sender. This
|
|
400
|
+
Delivery expeditions can only be in a shop for a certain amount of time before GLS returns them to the sender. This time limit is
|
|
522
401
|
calculated when the expedition is received at a shop and stored in its \`status.expiration\` field.
|
|
523
402
|
|
|
524
|
-
|
|
525
|
-
|
|
403
|
+
There are two values that need to be checked periodically: a list of moments when the customer needs to be reminded to pick up the
|
|
404
|
+
expedition, and the moment the expedition expires.
|
|
526
405
|
|
|
527
|
-
The API
|
|
528
|
-
is then the responsibility of some integration to respond to that historic record. See [integrations](#tag/Integrations-introduction)
|
|
529
|
-
for more information.`,
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
name: 'Integrations introduction',
|
|
533
|
-
'x-displayName': 'Integrations',
|
|
534
|
-
description: `
|
|
535
|
-
Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records in
|
|
536
|
-
chronological order and deciding what to do for each one, if anything. The integrations store their results in the \`integrations\` field
|
|
537
|
-
of each record.
|
|
538
|
-
|
|
539
|
-
Super administrators can search the historic records by integration name and result to find for example those records where the integration
|
|
540
|
-
failed and why. See the [historic records](#tag/Historic-records) endpoints for more information.
|
|
541
|
-
|
|
542
|
-
Each integration also has a corresponding \`integration\` document that stores its configuration, basically if it is enabled or not and
|
|
543
|
-
what networks it applies to:
|
|
406
|
+
The API runs two background processes that check these two values at regular intervals:
|
|
544
407
|
|
|
545
|
-
|
|
408
|
+
- One process checks when a reminder has expired and updates the expedition, moving said reminder from
|
|
409
|
+
\`status.expiration.pendingReminders\` to \`status.expiration.sentReminders\`.
|
|
410
|
+
- The other process checks when an expedition has expired and updates its \`status.code\` to \`expired\`.
|
|
546
411
|
|
|
547
|
-
|
|
412
|
+
Both processes only update an expedition and create the appropriate historic record. It is then the responsibility of other background
|
|
413
|
+
processes to do something in response to those historic records being created.`,
|
|
548
414
|
},
|
|
549
415
|
{
|
|
550
|
-
name: 'GLS Spain',
|
|
416
|
+
name: 'GLS Spain integration',
|
|
551
417
|
description: `
|
|
552
|
-
|
|
418
|
+
The API is integrated with the main systems of GLS Spain. The integration goes in both directions:
|
|
553
419
|
|
|
554
|
-
- GLS Spain has a super admin user to access
|
|
555
|
-
-
|
|
420
|
+
- GLS Spain has a super admin user to access the API and manage its resources, e.g. creating expeditions.
|
|
421
|
+
- The API runs a background process that watches the historic records and sends events to GLS.
|
|
556
422
|
|
|
557
423
|
This integration configuration can be found using the [find integrations endpoint](#tag/Integrations/paths/~1integrations~1find/post),
|
|
558
|
-
under the \`
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
|
564
|
-
|
|
|
565
|
-
| upsert
|
|
566
|
-
|
|
|
567
|
-
|
|
|
568
|
-
|
|
|
569
|
-
|
|
|
570
|
-
|
|
|
571
|
-
|
|
|
572
|
-
|
|
|
424
|
+
under the \`glsSpain\` name. Its \`networks\` field lists the networks that the shops, expeditions and sales must belong to for the events
|
|
425
|
+
to be sent. All other networks are ignored.
|
|
426
|
+
|
|
427
|
+
The following table lists the events that are sent along with the historic records that causes them:
|
|
428
|
+
|
|
429
|
+
| Event | Historic record |
|
|
430
|
+
| :--- | :--- |
|
|
431
|
+
| upsert network | Network update |
|
|
432
|
+
| upsert shop | Shop create or update |
|
|
433
|
+
| upsert sale | Sale create or update |
|
|
434
|
+
| receive from driver | Expedition update (received from driver) |
|
|
435
|
+
| receive from customer | Expedition update (received from customer) |
|
|
436
|
+
| give to customer | Expedition update (given to customer) |
|
|
437
|
+
| give to driver | Expedition update (given to driver) |
|
|
438
|
+
| expiration reminder | Expedition update (reminder moved from pending to sent) |
|
|
439
|
+
| expired | Expedition update (status changed to expired) |
|
|
440
|
+
| price | Expedition update (received from driver or customer)<br/>Expedition update (price changed after reception) |
|
|
573
441
|
|
|
574
442
|
The following are the request bodies sent for each event:
|
|
575
443
|
|
|
@@ -585,6 +453,12 @@ Sent when a shop is created or updated.
|
|
|
585
453
|
|
|
586
454
|
<SchemaDefinition schemaRef="#/components/schemas/upsertShopEvent" />
|
|
587
455
|
|
|
456
|
+
## Upsert sale event
|
|
457
|
+
|
|
458
|
+
Sent when a sale is created or updated.
|
|
459
|
+
|
|
460
|
+
<SchemaDefinition schemaRef="#/components/schemas/upsertSaleEvent" />
|
|
461
|
+
|
|
588
462
|
## Receive from driver event
|
|
589
463
|
|
|
590
464
|
Sent when a shop receives an expedition from a driver.
|
|
@@ -611,22 +485,42 @@ Sent when a shop delivers an expedition to a driver.
|
|
|
611
485
|
|
|
612
486
|
## Expiration reminder event
|
|
613
487
|
|
|
614
|
-
Sent when
|
|
488
|
+
Sent when an expedition expiration reminder has been moved from pending to sent.
|
|
615
489
|
|
|
616
490
|
<SchemaDefinition schemaRef="#/components/schemas/expirationReminderEvent" />
|
|
617
491
|
|
|
618
492
|
## Expired event
|
|
619
493
|
|
|
620
|
-
Sent when
|
|
494
|
+
Sent when an expedtions status has been changed to expired.
|
|
621
495
|
|
|
622
496
|
<SchemaDefinition schemaRef="#/components/schemas/expiredEvent" />
|
|
623
497
|
|
|
624
498
|
## Price event
|
|
625
499
|
|
|
626
|
-
Sent for the first time when an expedition is received at a shop, and after that any time the
|
|
500
|
+
Sent for the first time when an expedition is received at a shop, and after that any time the price is updated.
|
|
627
501
|
|
|
628
502
|
<SchemaDefinition schemaRef="#/components/schemas/priceEvent" />`,
|
|
629
503
|
},
|
|
504
|
+
{
|
|
505
|
+
name: 'GLS International integration',
|
|
506
|
+
description: `
|
|
507
|
+
The API is integrated with the GLS International ParcelShop API in order to export the shops in this API to the international database.
|
|
508
|
+
|
|
509
|
+
There is a background process that watches the historic records and each time a shop is created, updated or deleted, it is sent to the
|
|
510
|
+
international API.
|
|
511
|
+
|
|
512
|
+
This integration configuration can be found using the [find integrations endpoint](#tag/Integrations/paths/~1integrations~1find/post),
|
|
513
|
+
under the \`glsInternationalExport\` name. Its \`networks\` field lists the networks that the shops must belong to for them to be reported
|
|
514
|
+
to the international API. All other networks are ignored.`,
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: 'GLS SMS integration', // todo
|
|
518
|
+
description: `TODO`,
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'Ingenico integration', // todo
|
|
522
|
+
description: `TODO`,
|
|
523
|
+
},
|
|
630
524
|
{
|
|
631
525
|
name: 'Authentication',
|
|
632
526
|
description: `
|
|
@@ -652,74 +546,118 @@ The endpoints that require so will indicate it in their description.`,
|
|
|
652
546
|
{ name: 'Documentation' },
|
|
653
547
|
{
|
|
654
548
|
name: 'Config',
|
|
655
|
-
description: `API
|
|
549
|
+
description: `API global configuration.
|
|
550
|
+
|
|
551
|
+
This section contains the \`defaults\` object, which is a single object in the API that holds the configuration for:
|
|
552
|
+
|
|
553
|
+
- The derivation settings, which are the price rates for deliveries and pickups.
|
|
554
|
+
- The expiration settings, which include when do deliveries expire and when to send pickup reminders to the customers.
|
|
555
|
+
- The sales settings, which is the price table for sales based on the package size and destination.
|
|
556
|
+
|
|
557
|
+
The derivation and expiration settings can be overridden at the network and shop level if they need custom values other than the defaults.
|
|
558
|
+
|
|
559
|
+
The sales settings cannot be overridden at the network or shop levels. Instead, networks contain the percentages of the price that are paid
|
|
560
|
+
to the network and the shop.
|
|
561
|
+
|
|
562
|
+
This section also contains an endpoint to view the \`counters\` object, which keeps track of the last value used in each auto incremental
|
|
563
|
+
field used for any resource in the API.
|
|
656
564
|
|
|
657
|
-
|
|
565
|
+
## Defaults schema
|
|
658
566
|
|
|
659
|
-
|
|
660
|
-
and pickups, the maximum number of days that an expedition can be in a shop before returning it, etc.
|
|
567
|
+
### Sales price calculation
|
|
661
568
|
|
|
662
|
-
|
|
569
|
+
The API calculates the price for a destination (country and optional postal code) by scanning the \`salesSettings\` and following this steps:
|
|
663
570
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
571
|
+
1. For each zone:
|
|
572
|
+
1.1. If the destination is in \`excludes\` skip the zone.
|
|
573
|
+
1.2. Else if the destination is in \`includes\` save the match and the length of the prefix.
|
|
574
|
+
1.3. Else skip this zone.
|
|
575
|
+
2. If there is only one matched zone choose that one.
|
|
576
|
+
3. Else choose the first one among the matched zones with the longest prefix.
|
|
667
577
|
|
|
668
|
-
|
|
578
|
+
<SchemaDefinition schemaRef="#/components/schemas/defaults" />
|
|
579
|
+
|
|
580
|
+
## Counters schema
|
|
581
|
+
|
|
582
|
+
<SchemaDefinition schemaRef="#/components/schemas/counters" />`,
|
|
669
583
|
},
|
|
670
584
|
{
|
|
671
585
|
name: 'Super admins',
|
|
672
586
|
description: `Create and manage super admins.
|
|
673
587
|
|
|
674
|
-
Super
|
|
588
|
+
Super administrators can manage all the resources of the API.
|
|
589
|
+
|
|
590
|
+
An initial super admin is created when the API is deployed and then that super admin can create additional super admins.
|
|
591
|
+
|
|
592
|
+
## Super admin schema
|
|
593
|
+
|
|
594
|
+
<SchemaDefinition schemaRef="#/components/schemas/superAdmin" />
|
|
595
|
+
`,
|
|
675
596
|
},
|
|
676
597
|
{
|
|
677
598
|
name: 'Networks',
|
|
678
599
|
description: `Create and manage networks.
|
|
679
600
|
|
|
680
|
-
Networks
|
|
681
|
-
|
|
682
|
-
A network that has admins or parcel shops associated to it will have its \`deletable\` property automatically set to
|
|
683
|
-
\`false\` and cannot be deleted.
|
|
601
|
+
Networks represent the providers of parcel shops, e.g. the companies or associations that have a deal with GLS to use their establishments
|
|
602
|
+
as parcel shops. Every parcel shop belongs to a single network.
|
|
684
603
|
|
|
685
604
|
A network that has its \`readonly\` property set to \`true\` cannot be updated or have shops added to it. Readonly networks usually have
|
|
686
|
-
their shops come from
|
|
605
|
+
their shops come from an integration.
|
|
687
606
|
|
|
688
607
|
A network may have custom derivation and expiration settings or use the defaults defined in [config](#tag/Config):
|
|
689
608
|
|
|
690
609
|
- If it has \`derivationSettings\` or \`expirationSettings\` properties it means it has custom settings.
|
|
691
610
|
- If not, then the values in its \`defaults\` property will be used, which are a copy of the default values.
|
|
692
|
-
|
|
693
|
-
See [create](#tag/Networks/paths/~1networks~1create/post) and [update](#tag/Networks/paths/~1networks~1update/post) on
|
|
694
|
-
how to set or remove the custom properties.
|
|
695
611
|
|
|
696
|
-
|
|
612
|
+
## Network schema
|
|
613
|
+
|
|
614
|
+
<SchemaDefinition schemaRef="#/components/schemas/network" />`,
|
|
697
615
|
},
|
|
698
616
|
{
|
|
699
617
|
name: 'Network admins',
|
|
700
618
|
description: `Create and manage network admins.
|
|
701
619
|
|
|
702
|
-
Network admins are associated to a
|
|
620
|
+
Network admins are associated to a single network and can view its resources, like their shops and shop users.
|
|
621
|
+
|
|
622
|
+
## Network admin schema
|
|
623
|
+
|
|
624
|
+
<SchemaDefinition schemaRef="#/components/schemas/networkAdmin" />`,
|
|
703
625
|
},
|
|
704
626
|
{
|
|
705
627
|
name: 'Zones',
|
|
706
628
|
description: `Create and manage zones.
|
|
707
629
|
|
|
708
630
|
Zones define geographic areas that both the shops and the sales representatives are associated to. They define the commissions the sales
|
|
709
|
-
representatives earn for the shops they open or manage.
|
|
710
|
-
|
|
631
|
+
representatives earn for the shops they open or manage in that area.
|
|
632
|
+
|
|
633
|
+
## Zone schema
|
|
634
|
+
|
|
635
|
+
<SchemaDefinition schemaRef="#/components/schemas/zone" />`,
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: 'Sales representatives',
|
|
639
|
+
description: `Create and manage sales representatives.
|
|
640
|
+
|
|
641
|
+
Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop in the API
|
|
642
|
+
has two representatives associated to it: the one that made the deal to open the shop and the one that is currently managing it. They can
|
|
643
|
+
be the same representative.
|
|
644
|
+
|
|
645
|
+
## Sales representative schema
|
|
646
|
+
|
|
647
|
+
<SchemaDefinition schemaRef="#/components/schemas/representative" />`,
|
|
711
648
|
},
|
|
712
649
|
{
|
|
713
650
|
name: 'Shops',
|
|
714
651
|
description: `Create and manage shops.
|
|
715
652
|
|
|
716
|
-
|
|
653
|
+
Parcel shops are the establishments that GLS and the customers can use to deliver and pickup expeditions instead of doing
|
|
654
|
+
it at the customers home.
|
|
717
655
|
|
|
718
|
-
|
|
719
|
-
|
|
656
|
+
Every parcel shop is associated to a network on creation, and it must have at least one shop user associated to it for the parcel
|
|
657
|
+
shop to function.
|
|
720
658
|
|
|
721
659
|
A shop that has its \`readonly\` property set to \`true\` cannot be updated or have expeditions added to it. Readonly shops usually come
|
|
722
|
-
from
|
|
660
|
+
from an integration.
|
|
723
661
|
|
|
724
662
|
A shop may have custom derivation and expiration settings, use its network values or use the defaults defined in [config](#tag/Config):
|
|
725
663
|
|
|
@@ -728,9 +666,6 @@ A shop may have custom derivation and expiration settings, use its network value
|
|
|
728
666
|
- If it doesn't have settings in its \`network\` property then the values in its \`defaults\` property will be used, which are a copy of
|
|
729
667
|
the default values.
|
|
730
668
|
|
|
731
|
-
See [create](#tag/Shops/paths/~1shops~1create/post) and [update](#tag/Shops/paths/~1shops~1update/post) on how to set or remove
|
|
732
|
-
the custom properties.
|
|
733
|
-
|
|
734
669
|
### Status
|
|
735
670
|
|
|
736
671
|
A shop can be enabled or disabled as indicated by its \`status.code\` property. This property cannot be set directly,
|
|
@@ -742,30 +677,34 @@ instead its value depends on the other \`status\` properties:
|
|
|
742
677
|
| X | √ | \`disabled\` |
|
|
743
678
|
| X | X | \`enabled\` |
|
|
744
679
|
|
|
745
|
-
|
|
680
|
+
## Shop schema
|
|
681
|
+
|
|
682
|
+
<SchemaDefinition schemaRef="#/components/schemas/shop" />`,
|
|
746
683
|
},
|
|
747
684
|
{
|
|
748
685
|
name: 'Shop users',
|
|
749
686
|
description: `Create and manage shop users.
|
|
750
687
|
|
|
751
|
-
Shop users are associated with a single shop and they have limited capabilities to manage the shop and
|
|
688
|
+
Shop users are associated with a single shop and they have limited capabilities to manage the shop expeditions, e.g. they can receive and
|
|
689
|
+
deliver expeditions, but not edit anything else about them.
|
|
690
|
+
|
|
691
|
+
## Shop user schema
|
|
692
|
+
|
|
693
|
+
<SchemaDefinition schemaRef="#/components/schemas/shopUser" />`,
|
|
752
694
|
},
|
|
753
695
|
{
|
|
754
696
|
name: 'Expeditions',
|
|
755
697
|
description: `Create and manage expeditions.
|
|
756
698
|
|
|
757
|
-
Expeditions are the packages that are delivered and picked up
|
|
758
|
-
|
|
759
|
-
An expedition that has pods associated to it will have its \`deletable\` property automatically set to \`false\` and cannot be deleted.
|
|
699
|
+
Expeditions are the packages that are delivered and picked up at parcel shops.
|
|
760
700
|
|
|
761
701
|
### Types
|
|
762
702
|
|
|
763
|
-
There are
|
|
703
|
+
There are 2 kinds of expeditions, indicated in its \`type\` property:
|
|
764
704
|
|
|
765
|
-
- \`delivery\`:
|
|
766
|
-
- \`pickup\`:
|
|
767
|
-
|
|
768
|
-
at the parcel shop for a driver to retrieve it later.
|
|
705
|
+
- \`delivery\`: when a driver leaves an expedition at a parcel shop for the customer to retrieve it later.
|
|
706
|
+
- \`pickup\`: when a customer leaves an expedition at a parcel shop for the driver to retrieve it later. It can be because of a return or
|
|
707
|
+
a sale.
|
|
769
708
|
|
|
770
709
|
### Status
|
|
771
710
|
|
|
@@ -777,9 +716,8 @@ The \`status.code\` property of an expedition indicates the situation of an expe
|
|
|
777
716
|
The expedition is then scheduled to be given to the driver to return it to the original sender.
|
|
778
717
|
- \`delivered\`: the final status for any expedition, meaning that it has been given to the customer or driver and is no longer in the parcel shop.
|
|
779
718
|
|
|
780
|
-
The \`status\` of an expedition cannot be updated with a regular [update](#tag/Expeditions/paths/~1expeditions~1update/post)
|
|
781
|
-
|
|
782
|
-
\`status\` properties:
|
|
719
|
+
The \`status\` of an expedition cannot be updated with a regular [update](#tag/Expeditions/paths/~1expeditions~1update/post) because it has
|
|
720
|
+
a predetermined life cycle. The following endpoints update an expedition status and add or remove additional \`status\` properties:
|
|
783
721
|
|
|
784
722
|
| Operation | Type | From status | To status | New status properties |
|
|
785
723
|
| :--- | :--- | :--- | :--- | :--- |
|
|
@@ -790,25 +728,70 @@ because it has a predetermined life cycle. The following endpoints update an exp
|
|
|
790
728
|
| [giveToDriver](#tag/Expeditions/paths/~1expeditions~1giveToDriver/post) | delivery<br/>pickup | inShopExpired<br/>inShop | delivered<br/>delivered | givenTo<br/>givenTo |
|
|
791
729
|
| [redirect](#tag/Expeditions/paths/~1expeditions~1redirect/post) | any | any | incoming | clear everything |
|
|
792
730
|
|
|
793
|
-
|
|
731
|
+
## Expedition schema
|
|
732
|
+
|
|
733
|
+
<SchemaDefinition schemaRef="#/components/schemas/expedition" />`,
|
|
794
734
|
},
|
|
795
735
|
{
|
|
796
736
|
name: 'Pods',
|
|
797
|
-
description: `Find expeditions PODS (Proof Of Delivery)
|
|
737
|
+
description: `Find expeditions PODS (Proof Of Delivery).
|
|
738
|
+
|
|
739
|
+
When an expedition is picked up by a customer or delivered to a customer, the API will automatically create a POD with the customer
|
|
740
|
+
signature and reference the POD from the expedition \`status.receivedFrom.customer.pod\` or \`status.givenTo.customer.pod\` fields.
|
|
741
|
+
|
|
742
|
+
PODs are never updated or deleted even if their expedition is deleted, since they still need to be accessed from that expedition historic
|
|
743
|
+
records. Since they are part of their expedition historic records, PODs do not have historic records on their own.
|
|
744
|
+
|
|
745
|
+
## Pod schema
|
|
746
|
+
|
|
747
|
+
<SchemaDefinition schemaRef="#/components/schemas/pod" />`,
|
|
798
748
|
},
|
|
799
749
|
{
|
|
800
|
-
name: 'Sales
|
|
801
|
-
description: `Create and
|
|
750
|
+
name: 'Sales', // todo
|
|
751
|
+
description: `Create and find sales.
|
|
752
|
+
|
|
753
|
+
Customers can go to a parcel shop at any time and pay to have a package sent to an allowed destination.
|
|
754
|
+
|
|
755
|
+
The allowed destinations and the price of the service can be found in the [\`defaults\` object](#tag/Config/paths/~1config~1defaults~1get/get).
|
|
756
|
+
|
|
757
|
+
The process for a sale is the following:
|
|
802
758
|
|
|
803
|
-
|
|
759
|
+
- A shop user creates a sale by asking the customer for the destination and sender personal data, package size, etc.
|
|
760
|
+
- The API will use the Ingenico integration to prepare the payment and send the customer an SMS with a link where he can pay for the service.
|
|
761
|
+
- If Ingenico responds that the customer has paid the API will use the GLS Spain integration to notify GLS of the new sale.
|
|
762
|
+
- GLS Spain will then create a pickup expedition associated to the sale which will be picked up by a driver.
|
|
763
|
+
|
|
764
|
+
## Sale schema
|
|
765
|
+
|
|
766
|
+
<SchemaDefinition schemaRef="#/components/schemas/sale" />`,
|
|
804
767
|
},
|
|
805
768
|
{
|
|
806
769
|
name: 'Historic records',
|
|
807
|
-
description: `Find historic records
|
|
770
|
+
description: `Find historic records.
|
|
771
|
+
|
|
772
|
+
The \`actionKeys\` field lists the paths of the updated fields for an \`update\` action. The depth of the paths may vary:
|
|
773
|
+
|
|
774
|
+
- Usually it is just the keys at the root of the document, for example an update of any field in a shop address is just \`address\`.
|
|
775
|
+
- Some updates are more specific, for example delivering an expedition is \`status.code\` and \`status.givenTo\`.
|
|
776
|
+
|
|
777
|
+
The \`integrations\` field is where each integration stores what it did with the historic record. Its properties are the names of the
|
|
778
|
+
integrations and their values the result of that integration for that historic record.
|
|
779
|
+
|
|
780
|
+
## Historic record schema
|
|
781
|
+
|
|
782
|
+
<SchemaDefinition schemaRef="#/components/schemas/historicRecord" />`,
|
|
808
783
|
},
|
|
809
784
|
{
|
|
810
785
|
name: 'Integrations',
|
|
811
|
-
description: `Find integrations configurations
|
|
786
|
+
description: `Find integrations configurations.
|
|
787
|
+
|
|
788
|
+
Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records in
|
|
789
|
+
chronological order and deciding what to do for each one, if anything. The integrations store their results in the \`integrations\` field
|
|
790
|
+
of each record.
|
|
791
|
+
|
|
792
|
+
## Integration schema
|
|
793
|
+
|
|
794
|
+
<SchemaDefinition schemaRef="#/components/schemas/integration" />`,
|
|
812
795
|
},
|
|
813
796
|
];
|
|
814
797
|
|
|
@@ -874,6 +857,9 @@ const errors = {
|
|
|
874
857
|
zoneDoesNotExist: new ZoneDoesNotExistError(),
|
|
875
858
|
zoneAlreadyExists: new ZoneAlreadyExistsError(),
|
|
876
859
|
zoneCannotBeDeleted: new ZoneCannotBeDeletedError(),
|
|
860
|
+
saleAlreadyExists: new SaleAlreadyExistsError(),
|
|
861
|
+
inconsistentSalesSettings: new InconsistentSalesSettingsError(),
|
|
862
|
+
invalidSaleDestination: new InvalidSaleDestinationError(),
|
|
877
863
|
};
|
|
878
864
|
|
|
879
865
|
const responses = {
|
|
@@ -1021,6 +1007,18 @@ const responses = {
|
|
|
1021
1007
|
description: 'The zone cannot be deleted.',
|
|
1022
1008
|
content: { 'application/json': { schema: specificHttpError(errors.zoneCannotBeDeleted) } },
|
|
1023
1009
|
},
|
|
1010
|
+
saleAlreadyExists: {
|
|
1011
|
+
description: 'The sale already exists.',
|
|
1012
|
+
content: { 'application/json': { schema: specificHttpError(errors.saleAlreadyExists) } },
|
|
1013
|
+
},
|
|
1014
|
+
inconsistentSalesSettings: {
|
|
1015
|
+
description: 'The sales settings are inconsistent.',
|
|
1016
|
+
content: { 'application/json': { schema: specificHttpError(errors.inconsistentSalesSettings) } },
|
|
1017
|
+
},
|
|
1018
|
+
invalidSaleDestination: {
|
|
1019
|
+
description: 'The sale destination is invalid.',
|
|
1020
|
+
content: { 'application/json': { schema: specificHttpError(errors.invalidSaleDestination) } },
|
|
1021
|
+
},
|
|
1024
1022
|
};
|
|
1025
1023
|
|
|
1026
1024
|
const securitySchemes = {
|
|
@@ -1075,11 +1073,13 @@ openApiSpec.components = {
|
|
|
1075
1073
|
priceEvent: priceEvent(),
|
|
1076
1074
|
upsertShopEvent: upsertShopEvent(),
|
|
1077
1075
|
upsertNetworkEvent: upsertNetworkEvent(),
|
|
1076
|
+
upsertSaleEvent: upsertSaleEvent(),
|
|
1078
1077
|
timezoneNames: timezoneNames(),
|
|
1079
1078
|
representative: representative(),
|
|
1080
1079
|
zone: zone(),
|
|
1081
1080
|
historicRecord: historicRecord(),
|
|
1082
1081
|
integration: integration(),
|
|
1082
|
+
sale: sale(),
|
|
1083
1083
|
},
|
|
1084
1084
|
};
|
|
1085
1085
|
|
|
@@ -1237,32 +1237,6 @@ ${securitySchemes.basicAuth}`,
|
|
|
1237
1237
|
},
|
|
1238
1238
|
},
|
|
1239
1239
|
},
|
|
1240
|
-
'/config/init': {
|
|
1241
|
-
post: {
|
|
1242
|
-
tags: ['Config'],
|
|
1243
|
-
summary: '[!] Init API deployment',
|
|
1244
|
-
description: `
|
|
1245
|
-
Initializes and sets up the API when deployed in a new environment.
|
|
1246
|
-
|
|
1247
|
-
This initial super admin cannot be deleted later. You can add more super admins and disable this one's login though.
|
|
1248
|
-
|
|
1249
|
-
${securitySchemes.emptyDatabase}`,
|
|
1250
|
-
requestBody: {
|
|
1251
|
-
content: { 'application/json': { schema: initRequest() } },
|
|
1252
|
-
required: true,
|
|
1253
|
-
},
|
|
1254
|
-
responses: {
|
|
1255
|
-
' 200': {
|
|
1256
|
-
description: 'Contains the created super admin and default values.',
|
|
1257
|
-
content: { 'application/json': { schema: initResponse() } },
|
|
1258
|
-
},
|
|
1259
|
-
' 400': responses.badRequest,
|
|
1260
|
-
' 415': responses.unsupportedMediaType,
|
|
1261
|
-
' 500': responses.internalServerError,
|
|
1262
|
-
' 500 ': responses.databaseNotEmpty,
|
|
1263
|
-
},
|
|
1264
|
-
},
|
|
1265
|
-
},
|
|
1266
1240
|
'/config/defaults/get': {
|
|
1267
1241
|
get: {
|
|
1268
1242
|
tags: ['Config'],
|
|
@@ -1294,7 +1268,10 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1294
1268
|
description: `
|
|
1295
1269
|
Update the default settings.
|
|
1296
1270
|
|
|
1297
|
-
|
|
1271
|
+
If the \`derivationSettings\` or \`expirationSettings\` are updated, the update will propagate to the \`defaults\` property of all networks
|
|
1272
|
+
and shops.
|
|
1273
|
+
|
|
1274
|
+
If the \`salesSettings\` contains duplicated zones names the API will return a \`500 InconsistentSalesSettingsError\`.
|
|
1298
1275
|
|
|
1299
1276
|
${securitySchemes.tokens}
|
|
1300
1277
|
${securitySchemes.superAdminRole}`,
|
|
@@ -1316,6 +1293,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1316
1293
|
' 415': responses.unsupportedMediaType,
|
|
1317
1294
|
' 500': responses.internalServerError,
|
|
1318
1295
|
' 500 ': responses.defaultsDoNotExist,
|
|
1296
|
+
' 500 ': responses.inconsistentSalesSettings,
|
|
1319
1297
|
},
|
|
1320
1298
|
},
|
|
1321
1299
|
},
|
|
@@ -1981,6 +1959,9 @@ ${descriptions.createIdIsOptional}
|
|
|
1981
1959
|
|
|
1982
1960
|
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
1983
1961
|
|
|
1962
|
+
The \`zones\` property associates a representative with one or more zones. If any of the provided zones do not exist the API will return a
|
|
1963
|
+
\`500 ZoneDoesNotExistError\`.
|
|
1964
|
+
|
|
1984
1965
|
${securitySchemes.tokens}
|
|
1985
1966
|
${securitySchemes.superAdminRole}`,
|
|
1986
1967
|
requestBody: {
|
|
@@ -2000,7 +1981,8 @@ ${securitySchemes.superAdminRole}`,
|
|
|
2000
1981
|
' 403': responses.forbidden,
|
|
2001
1982
|
' 415': responses.unsupportedMediaType,
|
|
2002
1983
|
' 500': responses.internalServerError,
|
|
2003
|
-
' 500 ': responses.
|
|
1984
|
+
' 500 ': responses.zoneDoesNotExist,
|
|
1985
|
+
' 500 ': responses.representativeAlreadyExists,
|
|
2004
1986
|
},
|
|
2005
1987
|
},
|
|
2006
1988
|
},
|
|
@@ -3068,6 +3050,181 @@ ${securitySchemes.anyRole}`,
|
|
|
3068
3050
|
},
|
|
3069
3051
|
},
|
|
3070
3052
|
},
|
|
3053
|
+
'/sales/create': {
|
|
3054
|
+
post: {
|
|
3055
|
+
tags: ['Sales'],
|
|
3056
|
+
summary: '[U] Create',
|
|
3057
|
+
description: `
|
|
3058
|
+
Creates a new sale.
|
|
3059
|
+
|
|
3060
|
+
${descriptions.createIdIsOptional}
|
|
3061
|
+
|
|
3062
|
+
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
3063
|
+
|
|
3064
|
+
The \`network\` and \`shop\` fields of the new sale will be the same as the shop user that creates it.
|
|
3065
|
+
|
|
3066
|
+
The \`status.code\` will be \`pending\`.
|
|
3067
|
+
|
|
3068
|
+
The \`settings\` field will be created by combining the \`salesSettings\` from the \`default\` object and the \`salesSettings\` from the
|
|
3069
|
+
sale \`network\` as they are when the sale is created. This way the sale will keep the right settings values even if the \`default\` or
|
|
3070
|
+
the \`network\` are updated later.
|
|
3071
|
+
|
|
3072
|
+
The \`price\` field will be calculated from the \`size\` and \`settings\` fields.
|
|
3073
|
+
|
|
3074
|
+
${securitySchemes.tokens}
|
|
3075
|
+
${securitySchemes.shopUserRole}`,
|
|
3076
|
+
requestBody: {
|
|
3077
|
+
content: { 'application/json': { schema: createSaleRequest() } },
|
|
3078
|
+
required: true,
|
|
3079
|
+
},
|
|
3080
|
+
responses: {
|
|
3081
|
+
' 200': {
|
|
3082
|
+
description: 'Contains the created sale.',
|
|
3083
|
+
content: { 'application/json': { schema: createSaleResponse() } },
|
|
3084
|
+
},
|
|
3085
|
+
' 400': responses.badRequest,
|
|
3086
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3087
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3088
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3089
|
+
' 401 ': responses.unauthorized,
|
|
3090
|
+
' 403': responses.forbidden,
|
|
3091
|
+
' 415': responses.unsupportedMediaType,
|
|
3092
|
+
' 500': responses.internalServerError,
|
|
3093
|
+
' 500 ': responses.saleAlreadyExists,
|
|
3094
|
+
},
|
|
3095
|
+
},
|
|
3096
|
+
},
|
|
3097
|
+
'/sales/find': {
|
|
3098
|
+
post: {
|
|
3099
|
+
tags: ['Sales'],
|
|
3100
|
+
summary: '[S] Find',
|
|
3101
|
+
description: `
|
|
3102
|
+
Finds sales by one of several filters.
|
|
3103
|
+
|
|
3104
|
+
${descriptions.findLimitTip}
|
|
3105
|
+
|
|
3106
|
+
${securitySchemes.tokens}
|
|
3107
|
+
${securitySchemes.superAdminRole}`,
|
|
3108
|
+
requestBody: {
|
|
3109
|
+
content: { 'application/json': { schema: findSalesSuperAdminRequest() } },
|
|
3110
|
+
required: true,
|
|
3111
|
+
},
|
|
3112
|
+
responses: {
|
|
3113
|
+
' 200': {
|
|
3114
|
+
description: 'Contains the found sales.',
|
|
3115
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3116
|
+
},
|
|
3117
|
+
' 400': responses.badRequest,
|
|
3118
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3119
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3120
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3121
|
+
' 401 ': responses.unauthorized,
|
|
3122
|
+
' 403': responses.forbidden,
|
|
3123
|
+
' 415': responses.unsupportedMediaType,
|
|
3124
|
+
' 500': responses.internalServerError,
|
|
3125
|
+
},
|
|
3126
|
+
},
|
|
3127
|
+
},
|
|
3128
|
+
'/sales/find ': {
|
|
3129
|
+
post: {
|
|
3130
|
+
tags: ['Sales'],
|
|
3131
|
+
summary: '[N] Find',
|
|
3132
|
+
description: `
|
|
3133
|
+
Finds sales by one of several filters.
|
|
3134
|
+
|
|
3135
|
+
The results will be limited to the network the admin belongs to, so for example if he finds by \`_id\` and the sale is from another
|
|
3136
|
+
network, the find will return no results.
|
|
3137
|
+
|
|
3138
|
+
${descriptions.findLimitTip}
|
|
3139
|
+
|
|
3140
|
+
${securitySchemes.tokens}
|
|
3141
|
+
${securitySchemes.networkAdminRole}`,
|
|
3142
|
+
requestBody: {
|
|
3143
|
+
content: { 'application/json': { schema: findSalesNetworkAdminRequest() } },
|
|
3144
|
+
required: true,
|
|
3145
|
+
},
|
|
3146
|
+
responses: {
|
|
3147
|
+
' 200': {
|
|
3148
|
+
description: 'Contains the found sales.',
|
|
3149
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3150
|
+
},
|
|
3151
|
+
' 400': responses.badRequest,
|
|
3152
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3153
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3154
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3155
|
+
' 401 ': responses.unauthorized,
|
|
3156
|
+
' 403': responses.forbidden,
|
|
3157
|
+
' 415': responses.unsupportedMediaType,
|
|
3158
|
+
' 500': responses.internalServerError,
|
|
3159
|
+
},
|
|
3160
|
+
},
|
|
3161
|
+
},
|
|
3162
|
+
'/sales/find ': {
|
|
3163
|
+
post: {
|
|
3164
|
+
tags: ['Sales'],
|
|
3165
|
+
summary: '[U] Find',
|
|
3166
|
+
description: `
|
|
3167
|
+
Finds sales by one of several filters.
|
|
3168
|
+
|
|
3169
|
+
The results will be limited to the shop the user belongs to, so for example if he finds by \`_id\` and the sale is from another
|
|
3170
|
+
network or shop, the find will return no results.
|
|
3171
|
+
|
|
3172
|
+
${descriptions.findLimitTip}
|
|
3173
|
+
|
|
3174
|
+
${securitySchemes.tokens}
|
|
3175
|
+
${securitySchemes.shopUserRole}`,
|
|
3176
|
+
requestBody: {
|
|
3177
|
+
content: { 'application/json': { schema: findSalesShopUserRequest() } },
|
|
3178
|
+
required: true,
|
|
3179
|
+
},
|
|
3180
|
+
responses: {
|
|
3181
|
+
' 200': {
|
|
3182
|
+
description: 'Contains the found sales.',
|
|
3183
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3184
|
+
},
|
|
3185
|
+
' 400': responses.badRequest,
|
|
3186
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3187
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3188
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3189
|
+
' 401 ': responses.unauthorized,
|
|
3190
|
+
' 403': responses.forbidden,
|
|
3191
|
+
' 415': responses.unsupportedMediaType,
|
|
3192
|
+
' 500': responses.internalServerError,
|
|
3193
|
+
},
|
|
3194
|
+
},
|
|
3195
|
+
},
|
|
3196
|
+
'/sales/checkPrices': {
|
|
3197
|
+
post: {
|
|
3198
|
+
tags: ['Sales'],
|
|
3199
|
+
summary: '[SNU] Check prices',
|
|
3200
|
+
description: `
|
|
3201
|
+
Finds the price for a sale based on its package size and destination.
|
|
3202
|
+
|
|
3203
|
+
If the destination is invalid the API will return a \`500 InvalidSaleDestinationError\`.
|
|
3204
|
+
|
|
3205
|
+
${securitySchemes.tokens}
|
|
3206
|
+
${securitySchemes.anyRole}`,
|
|
3207
|
+
requestBody: {
|
|
3208
|
+
content: { 'application/json': { schema: checkSalePriceRequest() } },
|
|
3209
|
+
required: true,
|
|
3210
|
+
},
|
|
3211
|
+
responses: {
|
|
3212
|
+
' 200': {
|
|
3213
|
+
description: 'Contains the price of the sale.',
|
|
3214
|
+
content: { 'application/json': { schema: checkSalePriceResponse() } },
|
|
3215
|
+
},
|
|
3216
|
+
' 400': responses.badRequest,
|
|
3217
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3218
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3219
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3220
|
+
' 401 ': responses.unauthorized,
|
|
3221
|
+
' 403': responses.forbidden,
|
|
3222
|
+
' 415': responses.unsupportedMediaType,
|
|
3223
|
+
' 500': responses.internalServerError,
|
|
3224
|
+
' 500 ': responses.invalidSaleDestination,
|
|
3225
|
+
},
|
|
3226
|
+
},
|
|
3227
|
+
},
|
|
3071
3228
|
'/historicRecords/find': {
|
|
3072
3229
|
post: {
|
|
3073
3230
|
tags: ['Historic records'],
|
|
@@ -3109,8 +3266,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
3109
3266
|
description: `
|
|
3110
3267
|
Finds all the integrations of the API and what networks they apply to.
|
|
3111
3268
|
|
|
3112
|
-
To see what each integration
|
|
3113
|
-
section.
|
|
3269
|
+
To see what each integration does read the [background processes](#tag/Types-of-background-processes) section.
|
|
3114
3270
|
|
|
3115
3271
|
${descriptions.findLimitTip}
|
|
3116
3272
|
|