@gls_spain/gps-common 28.0.1 → 30.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.
@@ -118,7 +118,7 @@ const {
118
118
  receiveAllExpeditionsFromDriverRequest,
119
119
  receiveAllExpeditionsFromDriverResponse,
120
120
  } = require('../schemas/definitions/expeditions');
121
- const { getDefaultsResponse, updateDefaultsRequest, updateDefaultsResponse } = require('../schemas/definitions/defaults');
121
+ const { defaults, getDefaultsResponse, updateDefaultsRequest, updateDefaultsResponse } = require('../schemas/definitions/defaults');
122
122
  const { pod, findPodsRequest, findPodsResponse } = require('../schemas/definitions/pods');
123
123
  const {
124
124
  receiveFromDriverEvent,
@@ -158,13 +158,7 @@ const {
158
158
  deleteZoneResponse,
159
159
  } = require('../schemas/definitions/zones');
160
160
  const { integration, findIntegrationsRequest, findIntegrationsResponse } = require('../schemas/definitions/integrations');
161
- const {
162
- networkHistoricRecord,
163
- shopHistoricRecord,
164
- expeditionHistoricRecord,
165
- findHistoricRecordsRequest,
166
- findHistoricRecordsResponse,
167
- } = require('../schemas/definitions/historic-records');
161
+ const { historicRecord, findHistoricRecordsRequest, findHistoricRecordsResponse } = require('../schemas/definitions/historic-records');
168
162
 
169
163
  const openApiSpec = { openapi: '3.0.2' };
170
164
 
@@ -205,11 +199,11 @@ openApiSpec['x-tagGroups'] = [
205
199
  },
206
200
  {
207
201
  name: 'RESOURCES',
208
- tags: ['Super admin', 'Network', 'Network admin', 'Zone', 'Shop', 'Shop user', 'Expedition', 'Pod', 'Sales representative'],
202
+ tags: ['Defaults', 'Super admin', 'Network', 'Network admin', 'Zone', 'Shop', 'Shop user', 'Expedition', 'Pod', 'Sales representative'],
209
203
  },
210
204
  {
211
205
  name: 'HISTORIC RECORDS',
212
- tags: ['Historic records introduction', 'Network record', 'Shop record', 'Expedition record'],
206
+ tags: ['Historic records introduction'],
213
207
  },
214
208
  {
215
209
  name: 'BACKGROUND WORK',
@@ -225,17 +219,17 @@ openApiSpec['x-tagGroups'] = [
225
219
  'Authentication',
226
220
  'Documentation',
227
221
  'Config',
228
- 'Integrations',
229
222
  'Super admins',
230
223
  'Networks',
231
224
  'Network admins',
232
225
  'Zones',
226
+ 'Sales representatives',
233
227
  'Shops',
234
228
  'Shop users',
235
229
  'Expeditions',
236
230
  'Pods',
237
- 'Sales representatives',
238
231
  'Historic records',
232
+ 'Integrations',
239
233
  ],
240
234
  },
241
235
  ];
@@ -331,6 +325,16 @@ The full list of allowed timezone names is:
331
325
 
332
326
  <SchemaDefinition schemaRef="#/components/schemas/timezoneNames" />
333
327
  `,
328
+ },
329
+ {
330
+ name: 'Defaults',
331
+ description: `
332
+ The API has some default settings for networks and shops that do not specify their own, like the rate prices for deliveries and pickups,
333
+ the maximum number of days that an expedition can be in a shop before returning it, etc.
334
+
335
+ Super administrators can view and update this default settings using the [config](#tag/Config) endpoints.
336
+
337
+ <SchemaDefinition schemaRef="#/components/schemas/defaults" />`,
334
338
  },
335
339
  {
336
340
  name: 'Super admin',
@@ -370,6 +374,18 @@ Super administrators can create and manage zones using the [zones](#tag/Zones) e
370
374
  representatives on creation or update.
371
375
 
372
376
  <SchemaDefinition schemaRef="#/components/schemas/zone" />`,
377
+ },
378
+ {
379
+ name: 'Sales representative',
380
+ description: `
381
+ Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop
382
+ 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
383
+ managing it.
384
+
385
+ Super administrators can create and manage sales representatives using the [sales representatives](#tag/Sales-representatives)
386
+ endpoints, and then associate them to parcel shops on creation or update.
387
+
388
+ <SchemaDefinition schemaRef="#/components/schemas/representative" />`,
373
389
  },
374
390
  {
375
391
  name: 'Shop',
@@ -420,67 +436,36 @@ Super administrators, network administrators and shop users can use the [pods](#
420
436
  expeditions they have access to.
421
437
 
422
438
  <SchemaDefinition schemaRef="#/components/schemas/pod" />`,
423
- },
424
- {
425
- name: 'Sales representative',
426
- description: `
427
- Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop
428
- 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
429
- managing it.
430
-
431
- Super administrators can create and manage sales representatives using the [sales representatives](#tag/Sales-representatives)
432
- endpoints, and then associate them to parcel shops on creation or update.
433
-
434
- <SchemaDefinition schemaRef="#/components/schemas/representative" />`,
435
439
  },
436
440
  {
437
441
  name: 'Historic records introduction',
438
442
  'x-displayName': 'Historic records',
439
443
  description: `
440
- Every time the API creates, updates or deletes a network, shop or expedition, it stores a historic record of the action including the full
441
- document as it was after the action, the time it occurred and the user that made it.
442
-
443
- These historic records serve two purposes:
444
+ Every time the API creates, updates or deletes a resource, it stores a historic record of the action including the full document as it was
445
+ after the action, the time it occurred and the user that made it.
444
446
 
445
- - They allow to track the full history of a document and to revert any document to a previous state by updating it again.
446
- - They are the basis for integrations with other systems. Integrations work by iterating over the historic records in chronological order
447
- and deciding what to do with each action, if anything.
447
+ The only exception are \`pods\` which have no records because they are created when their expeditions are delivered and they are never
448
+ updated or deleted.
448
449
 
449
- Each record has an \`integrations\` field where each integration stores what it did with it.
450
- `,
451
- },
452
- {
453
- name: 'Network record',
454
- description: `
455
- The API creates a record every time a network is created, updated or deleted.
456
-
457
- Super administrators can search the historic records of networks using the [historic records](#tag/Historic-records) endpoints.
450
+ These historic records serve two purposes:
458
451
 
459
- <SchemaDefinition schemaRef="#/components/schemas/networkHistoricRecord" />`,
460
- },
461
- {
462
- name: 'Shop record',
463
- description: `
464
- The API creates a record every time a shop is created, updated or deleted.
452
+ - They allow to track the full history of a document.
453
+ - They are the basis for the [integrations](#tag/Integrations-introduction) with other systems.
465
454
 
466
- Super administrators can search the historic records of shops using the [historic records](#tag/Historic-records) endpoints.
455
+ The \`actionDetails\` field adds more information about the action when necessary, for example:
467
456
 
468
- <SchemaDefinition schemaRef="#/components/schemas/shopHistoricRecord" />`,
469
- },
470
- {
471
- name: 'Expedition record',
472
- description: `
473
- The API creates a record every time an expedition is created, updated, deleted, received, given or redirected.
457
+ - An expedition reception from a customer is an \`update\` action with the \`receiveFromCustomer\` and \`price\` details.
458
+ - An update of an expedition packages is an \`update\` action with a \`price\` detail.
459
+ - An automatic background expiration of an expedition is an \`update\` action with an \`expired\` detail.
474
460
 
475
- The \`actionExtras\` field contains additional information about the action. For example:
461
+ The values in \`actionDetails\` only apply to certain combinations of \`type\` and \`action\`.
476
462
 
477
- - A reception from a customer is an \`update\` action with the \`receiveFromCustomer\` and \`price\` extras.
478
- - An update of the packages is an \`update\` action with a \`price\` extra.
479
- - An automatic background expiration of an expedition is an \`update\` action with an \`expired\` extra.
463
+ The \`integrations\` field is where each integration stores what it did with it. Its properties are the names of the integrations and
464
+ their values the result of that integration for that record.
480
465
 
481
- Super administrators can search the historic records of expeditions using the [historic records](#tag/Historic-records) endpoints.
466
+ Super administrators can search the historic records using the [historic records](#tag/Historic-records) endpoints.
482
467
 
483
- <SchemaDefinition schemaRef="#/components/schemas/expeditionHistoricRecord" />`,
468
+ <SchemaDefinition schemaRef="#/components/schemas/historicRecord" />`,
484
469
  },
485
470
  {
486
471
  name: 'Background work',
@@ -525,9 +510,9 @@ for more information.`,
525
510
  name: 'Integrations introduction',
526
511
  'x-displayName': 'Integrations',
527
512
  description: `
528
- Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records of
529
- networks, shops and expeditions in chronological order and deciding what to do for each action, if anything. As these integrations iterate
530
- over the records they store their results in the \`integrations\` field of each record.
513
+ Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records in
514
+ chronological order and deciding what to do for each one, if anything. The integrations store their results in the \`integrations\` field
515
+ of each record.
531
516
 
532
517
  Super administrators can search the historic records by integration name and result to find for example those records where the integration
533
518
  failed and why. See the [historic records](#tag/Historic-records) endpoints for more information.
@@ -550,68 +535,73 @@ This API is integrated with the main systems of GLS Spain. The integration goes
550
535
  This integration configuration can be found using the [find integrations endpoint](#tag/Integrations/paths/~1integrations~1find/post),
551
536
  under the \`GLS Spain\` name. Its \`networks\` field lists the networks it applies to.
552
537
 
553
- The possible events sent to GLS Spain are listed below, along with the historic record that causes them to be sent.
538
+ The following table lists all the possible events along with the historic record that causes them to be sent:
539
+
540
+ | Event | Record type | Record action | Record details |
541
+ | :--- | :--- | :--- | :--- |
542
+ | upsert network | \`network\` | \`update\` | - |
543
+ | upsert shop | \`shop\` | \`create\` or \`update\` | - |
544
+ | receive from driver | \`expedition\` | \`update\` | \`receiveFromDriver\` |
545
+ | receive from customer | \`expedition\` | \`update\` | \`receiveFromCustomer\` |
546
+ | give to customer | \`expedition\` | \`update\` | \`giveToCustomer\` |
547
+ | give to driver | \`expedition\` | \`update\` | \`giveToDriver\` |
548
+ | expiration reminder | \`expedition\` | \`update\` | \`expirationReminder\` |
549
+ | expired | \`expedition\` | \`update\` | \`expired\` |
550
+ | price | \`expedition\` | \`update\` | \`price\` |
551
+
552
+ The following are the request bodies sent for each event:
554
553
 
555
554
  ## Upsert network event
556
555
 
557
- Sent when a network \`update\` record is found, which is created when the [/networks/update](#tag/Networks/paths/~1networks~1update/post)
558
- endpoint is called.
556
+ Sent when a network is updated.
559
557
 
560
558
  <SchemaDefinition schemaRef="#/components/schemas/upsertNetworkEvent" />
561
559
 
562
560
  ## Upsert shop event
563
561
 
564
- Sent when a shop \`create\` or \`update\` record is found, which are created when the
565
- [/shops/create](#tag/Shops/paths/~1shops~1create/post) or [/shops/update](#tag/Shops/paths/~1shops~1update/post) endpoints are called.
562
+ Sent when a shop is created or updated.
566
563
 
567
564
  <SchemaDefinition schemaRef="#/components/schemas/upsertShopEvent" />
568
565
 
569
566
  ## Receive from driver event
570
567
 
571
- Sent when an expedition \`update\` record with the \`receiveFromDriver\` extra is found, which is created when the
572
- [/expeditions/receiveFromDriver](#tag/Expeditions/paths/~1expeditions~1receiveFromDriver/post) endpoint is called.
568
+ Sent when a shop receives an expedition from a driver.
573
569
 
574
570
  <SchemaDefinition schemaRef="#/components/schemas/receiveFromDriverEvent" />
575
571
 
576
572
  ## Receive from customer event
577
573
 
578
- Sent when an expedition \`update\` record with the \`receiveFromCustomer\` extra is found, which is created when the
579
- [/expeditions/receiveFromCustomer](#tag/Expeditions/paths/~1expeditions~1receiveFromCustomer/post) is called.
574
+ Sent when a shop receives an expedition from a customer.
580
575
 
581
576
  <SchemaDefinition schemaRef="#/components/schemas/receiveFromCustomerEvent" />
582
577
 
583
578
  ## Give to customer event
584
579
 
585
- Sent when an expedition \`update\` record with the \`giveToCustomer\` extra is found, which is created when the
586
- [/expeditions/giveToCustomer](#tag/Expeditions/paths/~1expeditions~1giveToCustomer/post) endpoint is called.
580
+ Sent when a shop delivers an expedition to a customer.
587
581
 
588
582
  <SchemaDefinition schemaRef="#/components/schemas/giveToCustomerEvent" />
589
583
 
590
584
  ## Give to driver event
591
585
 
592
- Sent when an expedition \`update\` record with the \`giveToDriver\` extra is found, which is created when the
593
- [/expeditions/giveToDriver](#tag/Expeditions/paths/~1expeditions~1giveToDriver/post) endpoint is called.
586
+ Sent when a shop delivers an expedition to a driver.
594
587
 
595
588
  <SchemaDefinition schemaRef="#/components/schemas/giveToDriverEvent" />
596
589
 
597
590
  ## Expiration reminder event
598
591
 
599
- Sent when an expedition \`update\` record with the \`expirationReminder\` extra is found, which is created when the API detects in the
600
- background that it is time to remind the customer to pick up the expedition.
592
+ Sent when the API detects in the background that it is time to remind the customer to pick up the expedition and updates its status.
601
593
 
602
594
  <SchemaDefinition schemaRef="#/components/schemas/expirationReminderEvent" />
603
595
 
604
596
  ## Expired event
605
597
 
606
- Sent when an expedition \`update\` record with the \`expired\` extra is found, which is created when the API detects in the background that
607
- the expedition has expired and updates its status.
598
+ Sent when the API detects in the background that it is time to expire the expedition and updates its status.
608
599
 
609
600
  <SchemaDefinition schemaRef="#/components/schemas/expiredEvent" />
610
601
 
611
602
  ## Price event
612
603
 
613
- Sent when an expedition \`update\` record with the \`price\` extra is found, which is created when the expedition is received and after
614
- that anytime the weight or packages are updated.
604
+ Sent for the first time when an expedition is received at a shop, and after that any time the weight or packages are updated.
615
605
 
616
606
  <SchemaDefinition schemaRef="#/components/schemas/priceEvent" />`,
617
607
  },
@@ -1022,6 +1012,7 @@ Any optional array property that is not provided will default to an empty array.
1022
1012
  openApiSpec.components = {
1023
1013
  schemas: {
1024
1014
  errorResponse: errorResponse(),
1015
+ defaults: defaults(),
1025
1016
  superAdmin: superAdmin(),
1026
1017
  networkAdmin: networkAdmin(),
1027
1018
  shopUser: shopUser(),
@@ -1041,9 +1032,7 @@ openApiSpec.components = {
1041
1032
  timezoneNames: timezoneNames(),
1042
1033
  representative: representative(),
1043
1034
  zone: zone(),
1044
- networkHistoricRecord: networkHistoricRecord(),
1045
- shopHistoricRecord: shopHistoricRecord(),
1046
- expeditionHistoricRecord: expeditionHistoricRecord(),
1035
+ historicRecord: historicRecord(),
1047
1036
  integration: integration(),
1048
1037
  },
1049
1038
  };
@@ -1284,40 +1273,6 @@ ${securitySchemes.superAdminRole}`,
1284
1273
  },
1285
1274
  },
1286
1275
  },
1287
- '/integrations/find': {
1288
- post: {
1289
- tags: ['Integrations'],
1290
- summary: '[S] Find',
1291
- description: `
1292
- Finds all the integrations of the API and what networks they apply to.
1293
-
1294
- To see what each integration actually does read that integration documentation in the [integrations](#tag/Integrations-introduction)
1295
- section.
1296
-
1297
- ${descriptions.findLimitTip}
1298
-
1299
- ${securitySchemes.tokens}
1300
- ${securitySchemes.superAdminRole}`,
1301
- requestBody: {
1302
- content: { 'application/json': { schema: findIntegrationsRequest() } },
1303
- required: true,
1304
- },
1305
- responses: {
1306
- ' 200': {
1307
- description: 'Contains the found integrations.',
1308
- content: { 'application/json': { schema: findIntegrationsResponse() } },
1309
- },
1310
- ' 400': responses.badRequest,
1311
- ' 401': responses.invalidUserInCookieOrHeader,
1312
- ' 401 ': responses.invalidCookieOrHeader,
1313
- ' 401 ': responses.missingCookieOrHeader,
1314
- ' 401 ': responses.unauthorized,
1315
- ' 403': responses.forbidden,
1316
- ' 415': responses.unsupportedMediaType,
1317
- ' 500': responses.internalServerError,
1318
- },
1319
- },
1320
- },
1321
1276
  '/superAdmins/create': {
1322
1277
  post: {
1323
1278
  tags: ['Super admins'],
@@ -1946,6 +1901,196 @@ ${securitySchemes.superAdminRole}`,
1946
1901
  },
1947
1902
  },
1948
1903
  },
1904
+ '/representatives/create': {
1905
+ post: {
1906
+ tags: ['Sales representatives'],
1907
+ summary: '[S] Create',
1908
+ description: `
1909
+ Creates a new sales representative.
1910
+
1911
+ ${descriptions.createIdIsOptional}
1912
+
1913
+ ${descriptions.optionalArrayPropertiesEmptyByDefault}
1914
+
1915
+ ${securitySchemes.tokens}
1916
+ ${securitySchemes.superAdminRole}`,
1917
+ requestBody: {
1918
+ content: { 'application/json': { schema: createRepresentativeRequest() } },
1919
+ required: true,
1920
+ },
1921
+ responses: {
1922
+ ' 200': {
1923
+ description: 'Contains the created sales representative.',
1924
+ content: { 'application/json': { schema: createRepresentativeResponse() } },
1925
+ },
1926
+ ' 400': responses.badRequest,
1927
+ ' 401': responses.invalidUserInCookieOrHeader,
1928
+ ' 401 ': responses.invalidCookieOrHeader,
1929
+ ' 401 ': responses.missingCookieOrHeader,
1930
+ ' 401 ': responses.unauthorized,
1931
+ ' 403': responses.forbidden,
1932
+ ' 415': responses.unsupportedMediaType,
1933
+ ' 500': responses.internalServerError,
1934
+ ' 500 ': responses.representativeAlreadyExists,
1935
+ },
1936
+ },
1937
+ },
1938
+ '/representatives/listNames': {
1939
+ get: {
1940
+ tags: ['Sales representatives'],
1941
+ summary: '[S] List names',
1942
+ description: `
1943
+ Finds sales representatives and returns only the \`_id\` and \`name\` properties for each one.
1944
+
1945
+ ${securitySchemes.tokens}
1946
+ ${securitySchemes.superAdminRole}`,
1947
+ responses: {
1948
+ ' 200': {
1949
+ description: 'Contains the found sales representatives names.',
1950
+ content: { 'application/json': { schema: listRepresentativesNamesResponse() } },
1951
+ },
1952
+ ' 400': responses.badRequest,
1953
+ ' 401': responses.invalidUserInCookieOrHeader,
1954
+ ' 401 ': responses.invalidCookieOrHeader,
1955
+ ' 401 ': responses.missingCookieOrHeader,
1956
+ ' 401 ': responses.unauthorized,
1957
+ ' 403': responses.forbidden,
1958
+ ' 415': responses.unsupportedMediaType,
1959
+ ' 500': responses.internalServerError,
1960
+ },
1961
+ },
1962
+ },
1963
+ '/representatives/find': {
1964
+ post: {
1965
+ tags: ['Sales representatives'],
1966
+ summary: '[S] Find',
1967
+ description: `
1968
+ Finds sales representatives by one of several filters.
1969
+
1970
+ ${descriptions.findLimitTip}
1971
+
1972
+ ${securitySchemes.tokens}
1973
+ ${securitySchemes.superAdminRole}`,
1974
+ requestBody: {
1975
+ content: { 'application/json': { schema: findRepresentativesRequest() } },
1976
+ required: true,
1977
+ },
1978
+ responses: {
1979
+ ' 200': {
1980
+ description: 'Contains the found sales representatives.',
1981
+ content: { 'application/json': { schema: findRepresentativesResponse() } },
1982
+ },
1983
+ ' 400': responses.badRequest,
1984
+ ' 401': responses.invalidUserInCookieOrHeader,
1985
+ ' 401 ': responses.invalidCookieOrHeader,
1986
+ ' 401 ': responses.missingCookieOrHeader,
1987
+ ' 401 ': responses.unauthorized,
1988
+ ' 403': responses.forbidden,
1989
+ ' 415': responses.unsupportedMediaType,
1990
+ ' 500': responses.internalServerError,
1991
+ },
1992
+ },
1993
+ },
1994
+ '/representatives/update': {
1995
+ post: {
1996
+ tags: ['Sales representatives'],
1997
+ summary: '[S] Update',
1998
+ description: `
1999
+ Finds a sales representative and updates the provided properties.
2000
+
2001
+ ${descriptions.updateSetAddOrRemove}
2002
+
2003
+ ${securitySchemes.tokens}
2004
+ ${securitySchemes.superAdminRole}`,
2005
+ requestBody: {
2006
+ content: { 'application/json': { schema: updateRepresentativeRequest() } },
2007
+ required: true,
2008
+ },
2009
+ responses: {
2010
+ ' 200': {
2011
+ description: 'Contains the updated sales representative.',
2012
+ content: { 'application/json': { schema: updateRepresentativeResponse() } },
2013
+ },
2014
+ ' 400': responses.badRequest,
2015
+ ' 401': responses.invalidUserInCookieOrHeader,
2016
+ ' 401 ': responses.invalidCookieOrHeader,
2017
+ ' 401 ': responses.missingCookieOrHeader,
2018
+ ' 401 ': responses.unauthorized,
2019
+ ' 403': responses.forbidden,
2020
+ ' 415': responses.unsupportedMediaType,
2021
+ ' 500': responses.internalServerError,
2022
+ ' 500 ': responses.representativeDoesNotExist,
2023
+ },
2024
+ },
2025
+ },
2026
+ '/representatives/getCommissions': {
2027
+ post: {
2028
+ tags: ['Sales representatives'],
2029
+ summary: '[S] Get commissions',
2030
+ description: `
2031
+ Gets the commissions earned by a representative between two dates.
2032
+
2033
+ The commissions are calculated by zones. For each zone the commissions include how many shops the representative has opened in that date
2034
+ range and how many shops he has been managing for more than X months. The minimum shops he has to open and for how long he has to manage
2035
+ shops is configured in the zone commissions.
2036
+
2037
+ ${securitySchemes.tokens}
2038
+ ${securitySchemes.superAdminRole}`,
2039
+ requestBody: {
2040
+ content: { 'application/json': { schema: getRepresentativeCommissionsRequest() } },
2041
+ required: true,
2042
+ },
2043
+ responses: {
2044
+ ' 200': {
2045
+ description: 'Contains the commissions for that representative and date range.',
2046
+ content: { 'application/json': { schema: getRepresentativeCommissionsResponse() } },
2047
+ },
2048
+ ' 400': responses.badRequest,
2049
+ ' 401': responses.invalidUserInCookieOrHeader,
2050
+ ' 401 ': responses.invalidCookieOrHeader,
2051
+ ' 401 ': responses.missingCookieOrHeader,
2052
+ ' 401 ': responses.unauthorized,
2053
+ ' 403': responses.forbidden,
2054
+ ' 415': responses.unsupportedMediaType,
2055
+ ' 500': responses.internalServerError,
2056
+ ' 500 ': responses.representativeDoesNotExist,
2057
+ },
2058
+ },
2059
+ },
2060
+ '/representatives/delete': {
2061
+ post: {
2062
+ tags: ['Sales representatives'],
2063
+ summary: '[S] Delete',
2064
+ description: `
2065
+ Deletes a sales representative.
2066
+
2067
+ A sales representative whose \`deletable\` property is \`false\` cannot be deleted because it has shops associated to it.
2068
+ If you try the API will return a \`500 RepresentativeCannotBeDeletedError\`.
2069
+
2070
+ ${securitySchemes.tokens}
2071
+ ${securitySchemes.superAdminRole}`,
2072
+ requestBody: {
2073
+ content: { 'application/json': { schema: deleteRepresentativeRequest() } },
2074
+ required: true,
2075
+ },
2076
+ responses: {
2077
+ ' 200': {
2078
+ description: 'Contains the deleted sales representative.',
2079
+ content: { 'application/json': { schema: deleteRepresentativeResponse() } },
2080
+ },
2081
+ ' 400': responses.badRequest,
2082
+ ' 401': responses.invalidUserInCookieOrHeader,
2083
+ ' 401 ': responses.invalidCookieOrHeader,
2084
+ ' 401 ': responses.missingCookieOrHeader,
2085
+ ' 401 ': responses.unauthorized,
2086
+ ' 403': responses.forbidden,
2087
+ ' 415': responses.unsupportedMediaType,
2088
+ ' 500': responses.internalServerError,
2089
+ ' 500 ': responses.representativeDoesNotExist,
2090
+ ' 500 ': responses.representativeCannotBeDeleted,
2091
+ },
2092
+ },
2093
+ },
1949
2094
  '/shops/create': {
1950
2095
  post: {
1951
2096
  tags: ['Shops'],
@@ -2814,182 +2959,28 @@ ${securitySchemes.anyRole}`,
2814
2959
  },
2815
2960
  },
2816
2961
  },
2817
- '/representatives/create': {
2818
- post: {
2819
- tags: ['Sales representatives'],
2820
- summary: '[S] Create',
2821
- description: `
2822
- Creates a new sales representative.
2823
-
2824
- ${descriptions.createIdIsOptional}
2825
-
2826
- ${descriptions.optionalArrayPropertiesEmptyByDefault}
2827
-
2828
- ${securitySchemes.tokens}
2829
- ${securitySchemes.superAdminRole}`,
2830
- requestBody: {
2831
- content: { 'application/json': { schema: createRepresentativeRequest() } },
2832
- required: true,
2833
- },
2834
- responses: {
2835
- ' 200': {
2836
- description: 'Contains the created sales representative.',
2837
- content: { 'application/json': { schema: createRepresentativeResponse() } },
2838
- },
2839
- ' 400': responses.badRequest,
2840
- ' 401': responses.invalidUserInCookieOrHeader,
2841
- ' 401 ': responses.invalidCookieOrHeader,
2842
- ' 401 ': responses.missingCookieOrHeader,
2843
- ' 401 ': responses.unauthorized,
2844
- ' 403': responses.forbidden,
2845
- ' 415': responses.unsupportedMediaType,
2846
- ' 500': responses.internalServerError,
2847
- ' 500 ': responses.representativeAlreadyExists,
2848
- },
2849
- },
2850
- },
2851
- '/representatives/listNames': {
2852
- get: {
2853
- tags: ['Sales representatives'],
2854
- summary: '[S] List names',
2855
- description: `
2856
- Finds sales representatives and returns only the \`_id\` and \`name\` properties for each one.
2857
-
2858
- ${securitySchemes.tokens}
2859
- ${securitySchemes.superAdminRole}`,
2860
- responses: {
2861
- ' 200': {
2862
- description: 'Contains the found sales representatives names.',
2863
- content: { 'application/json': { schema: listRepresentativesNamesResponse() } },
2864
- },
2865
- ' 400': responses.badRequest,
2866
- ' 401': responses.invalidUserInCookieOrHeader,
2867
- ' 401 ': responses.invalidCookieOrHeader,
2868
- ' 401 ': responses.missingCookieOrHeader,
2869
- ' 401 ': responses.unauthorized,
2870
- ' 403': responses.forbidden,
2871
- ' 415': responses.unsupportedMediaType,
2872
- ' 500': responses.internalServerError,
2873
- },
2874
- },
2875
- },
2876
- '/representatives/find': {
2962
+ '/historicRecords/find': {
2877
2963
  post: {
2878
- tags: ['Sales representatives'],
2964
+ tags: ['Historic records'],
2879
2965
  summary: '[S] Find',
2880
2966
  description: `
2881
- Finds sales representatives by one of several filters.
2882
-
2883
- ${descriptions.findLimitTip}
2884
-
2885
- ${securitySchemes.tokens}
2886
- ${securitySchemes.superAdminRole}`,
2887
- requestBody: {
2888
- content: { 'application/json': { schema: findRepresentativesRequest() } },
2889
- required: true,
2890
- },
2891
- responses: {
2892
- ' 200': {
2893
- description: 'Contains the found sales representatives.',
2894
- content: { 'application/json': { schema: findRepresentativesResponse() } },
2895
- },
2896
- ' 400': responses.badRequest,
2897
- ' 401': responses.invalidUserInCookieOrHeader,
2898
- ' 401 ': responses.invalidCookieOrHeader,
2899
- ' 401 ': responses.missingCookieOrHeader,
2900
- ' 401 ': responses.unauthorized,
2901
- ' 403': responses.forbidden,
2902
- ' 415': responses.unsupportedMediaType,
2903
- ' 500': responses.internalServerError,
2904
- },
2905
- },
2906
- },
2907
- '/representatives/update': {
2908
- post: {
2909
- tags: ['Sales representatives'],
2910
- summary: '[S] Update',
2911
- description: `
2912
- Finds a sales representative and updates the provided properties.
2913
-
2914
- ${descriptions.updateSetAddOrRemove}
2915
-
2916
- ${securitySchemes.tokens}
2917
- ${securitySchemes.superAdminRole}`,
2918
- requestBody: {
2919
- content: { 'application/json': { schema: updateRepresentativeRequest() } },
2920
- required: true,
2921
- },
2922
- responses: {
2923
- ' 200': {
2924
- description: 'Contains the updated sales representative.',
2925
- content: { 'application/json': { schema: updateRepresentativeResponse() } },
2926
- },
2927
- ' 400': responses.badRequest,
2928
- ' 401': responses.invalidUserInCookieOrHeader,
2929
- ' 401 ': responses.invalidCookieOrHeader,
2930
- ' 401 ': responses.missingCookieOrHeader,
2931
- ' 401 ': responses.unauthorized,
2932
- ' 403': responses.forbidden,
2933
- ' 415': responses.unsupportedMediaType,
2934
- ' 500': responses.internalServerError,
2935
- ' 500 ': responses.representativeDoesNotExist,
2936
- },
2937
- },
2938
- },
2939
- '/representatives/getCommissions': {
2940
- post: {
2941
- tags: ['Sales representatives'],
2942
- summary: '[S] Get commissions',
2943
- description: `
2944
- Gets the commissions earned by a representative between two dates.
2967
+ Finds historic records of resources or integration results.
2945
2968
 
2946
- The commissions are calculated by zones. For each zone the commissions include how many shops the representative has opened in that date
2947
- range and how many shops he has been managing for more than X months. The minimum shops he has to open and for how long he has to manage
2948
- shops is configured in the zone commissions.
2969
+ You can find all the records for a single resource or all the records processed by a single integration and with a specific result,
2970
+ for example \`failed\`.
2949
2971
 
2950
- ${securitySchemes.tokens}
2951
- ${securitySchemes.superAdminRole}`,
2952
- requestBody: {
2953
- content: { 'application/json': { schema: getRepresentativeCommissionsRequest() } },
2954
- required: true,
2955
- },
2956
- responses: {
2957
- ' 200': {
2958
- description: 'Contains the commissions for that representative and date range.',
2959
- content: { 'application/json': { schema: getRepresentativeCommissionsResponse() } },
2960
- },
2961
- ' 400': responses.badRequest,
2962
- ' 401': responses.invalidUserInCookieOrHeader,
2963
- ' 401 ': responses.invalidCookieOrHeader,
2964
- ' 401 ': responses.missingCookieOrHeader,
2965
- ' 401 ': responses.unauthorized,
2966
- ' 403': responses.forbidden,
2967
- ' 415': responses.unsupportedMediaType,
2968
- ' 500': responses.internalServerError,
2969
- ' 500 ': responses.representativeDoesNotExist,
2970
- },
2971
- },
2972
- },
2973
- '/representatives/delete': {
2974
- post: {
2975
- tags: ['Sales representatives'],
2976
- summary: '[S] Delete',
2977
- description: `
2978
- Deletes a sales representative.
2979
-
2980
- A sales representative whose \`deletable\` property is \`false\` cannot be deleted because it has shops associated to it.
2981
- If you try the API will return a \`500 RepresentativeCannotBeDeletedError\`.
2972
+ ${descriptions.findLimitTip}
2982
2973
 
2983
2974
  ${securitySchemes.tokens}
2984
2975
  ${securitySchemes.superAdminRole}`,
2985
2976
  requestBody: {
2986
- content: { 'application/json': { schema: deleteRepresentativeRequest() } },
2977
+ content: { 'application/json': { schema: findHistoricRecordsRequest() } },
2987
2978
  required: true,
2988
2979
  },
2989
2980
  responses: {
2990
2981
  ' 200': {
2991
- description: 'Contains the deleted sales representative.',
2992
- content: { 'application/json': { schema: deleteRepresentativeResponse() } },
2982
+ description: 'Contains the found historic records.',
2983
+ content: { 'application/json': { schema: findHistoricRecordsResponse() } },
2993
2984
  },
2994
2985
  ' 400': responses.badRequest,
2995
2986
  ' 401': responses.invalidUserInCookieOrHeader,
@@ -2999,33 +2990,31 @@ ${securitySchemes.superAdminRole}`,
2999
2990
  ' 403': responses.forbidden,
3000
2991
  ' 415': responses.unsupportedMediaType,
3001
2992
  ' 500': responses.internalServerError,
3002
- ' 500 ': responses.representativeDoesNotExist,
3003
- ' 500 ': responses.representativeCannotBeDeleted,
3004
2993
  },
3005
2994
  },
3006
2995
  },
3007
- '/history/find': {
2996
+ '/integrations/find': {
3008
2997
  post: {
3009
- tags: ['Historic records'],
2998
+ tags: ['Integrations'],
3010
2999
  summary: '[S] Find',
3011
3000
  description: `
3012
- Finds historic records of networks, shops and expeditions.
3001
+ Finds all the integrations of the API and what networks they apply to.
3013
3002
 
3014
- You can find all the records for a single network, shop or expedition, or all the records processed by a single integration and with a
3015
- specific result, for example \`failed\`.
3003
+ To see what each integration actually does read that integration documentation in the [integrations](#tag/Integrations-introduction)
3004
+ section.
3016
3005
 
3017
3006
  ${descriptions.findLimitTip}
3018
3007
 
3019
3008
  ${securitySchemes.tokens}
3020
3009
  ${securitySchemes.superAdminRole}`,
3021
3010
  requestBody: {
3022
- content: { 'application/json': { schema: findHistoricRecordsRequest() } },
3011
+ content: { 'application/json': { schema: findIntegrationsRequest() } },
3023
3012
  required: true,
3024
3013
  },
3025
3014
  responses: {
3026
3015
  ' 200': {
3027
- description: 'Contains the found historic records.',
3028
- content: { 'application/json': { schema: findHistoricRecordsResponse() } },
3016
+ description: 'Contains the found integrations.',
3017
+ content: { 'application/json': { schema: findIntegrationsResponse() } },
3029
3018
  },
3030
3019
  ' 400': responses.badRequest,
3031
3020
  ' 401': responses.invalidUserInCookieOrHeader,