@gls_spain/gps-common 27.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/.eslintrc.json +11 -0
- package/.idea/codeStyles/Project.xml +37 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/gps-common.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/watcherTasks.xml +45 -0
- package/.prettierignore +5 -0
- package/.prettierrc.json +13 -0
- package/.releaserc +17 -0
- package/CHANGELOG.md +848 -0
- package/README.md +122 -0
- package/errors/DatabaseNotEmptyError.js +9 -0
- package/errors/DefaultsDoNotExistError.js +9 -0
- package/errors/ExpeditionAlreadyExistsError.js +9 -0
- package/errors/ExpeditionCannotBeDeletedError.js +9 -0
- package/errors/ExpeditionCannotBeUpdatedError.js +9 -0
- package/errors/ExpeditionDoesNotExistError.js +9 -0
- package/errors/JobDoesNotExistError.js +9 -0
- package/errors/NetworkAlreadyExistsError.js +9 -0
- package/errors/NetworkCannotBeDeletedError.js +9 -0
- package/errors/NetworkDoesNotExistError.js +9 -0
- package/errors/RepresentativeAlreadyExistsError.js +9 -0
- package/errors/RepresentativeCannotBeDeletedError.js +9 -0
- package/errors/RepresentativeDoesNotExistError.js +9 -0
- package/errors/ShopAlreadyExistsError.js +9 -0
- package/errors/ShopCannotBeDeletedError.js +9 -0
- package/errors/ShopDoesNotExistError.js +9 -0
- package/errors/ShopNotEnabledError.js +9 -0
- package/errors/UserAlreadyExistsError.js +9 -0
- package/errors/UserCannotBeDeletedError.js +9 -0
- package/errors/UserCannotBeUpdatedError.js +9 -0
- package/errors/UserDoesNotExistError.js +9 -0
- package/errors/WrongNetworkError.js +9 -0
- package/errors/WrongPasswordError.js +9 -0
- package/errors/WrongShopError.js +9 -0
- package/errors/ZoneAlreadyExistsError.js +9 -0
- package/errors/ZoneCannotBeDeletedError.js +9 -0
- package/errors/ZoneDoesNotExistError.js +9 -0
- package/errors/index.js +88 -0
- package/index.js +9 -0
- package/index.test.js +35 -0
- package/jest.config.js +5 -0
- package/open-api-spec/index.js +2920 -0
- package/package.json +68 -0
- package/schemas/definitions/become.js +5 -0
- package/schemas/definitions/common.js +172 -0
- package/schemas/definitions/defaults.js +84 -0
- package/schemas/definitions/expeditions.js +637 -0
- package/schemas/definitions/init.js +37 -0
- package/schemas/definitions/integration-events.js +127 -0
- package/schemas/definitions/jobs.js +124 -0
- package/schemas/definitions/login.js +38 -0
- package/schemas/definitions/logout.js +8 -0
- package/schemas/definitions/networks.js +107 -0
- package/schemas/definitions/pods.js +37 -0
- package/schemas/definitions/representatives.js +178 -0
- package/schemas/definitions/shops.js +352 -0
- package/schemas/definitions/users.js +373 -0
- package/schemas/definitions/zones.js +92 -0
- package/schemas/index.js +335 -0
- package/scripts/build-documentation.js +40 -0
- package/scripts/build-json-schemas.js +35 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const { mergeSchemas } = require('@gls_spain/common-json-schemas');
|
|
2
|
+
const { date } = require('./common');
|
|
3
|
+
const { expedition, processedWithDriver, processedWithCustomerWithPod } = require('./expeditions');
|
|
4
|
+
const { shop, objectWithShopId } = require('./shops');
|
|
5
|
+
const { network, objectWithNetworkId } = require('./networks');
|
|
6
|
+
|
|
7
|
+
const objectWithExpirationDate = () => ({
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: { expirationDate: date() },
|
|
10
|
+
required: ['expirationDate'],
|
|
11
|
+
additionalProperties: false,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const receiveFromDriverEvent = () => ({
|
|
15
|
+
title: 'receive from driver',
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
_id: expedition().properties._id,
|
|
19
|
+
receiveFromDriver: mergeSchemas(processedWithDriver(), objectWithShopId(), objectWithNetworkId(), objectWithExpirationDate()),
|
|
20
|
+
},
|
|
21
|
+
required: ['_id', 'receiveFromDriver'],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const receiveFromCustomerEvent = () => ({
|
|
26
|
+
title: 'receive from customer',
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
_id: expedition().properties._id,
|
|
30
|
+
receiveFromCustomer: mergeSchemas(
|
|
31
|
+
processedWithCustomerWithPod(),
|
|
32
|
+
objectWithShopId(),
|
|
33
|
+
objectWithNetworkId(),
|
|
34
|
+
objectWithExpirationDate(),
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
required: ['_id', 'receiveFromCustomer'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const giveToCustomerEvent = () => ({
|
|
42
|
+
title: 'give to customer',
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
_id: expedition().properties._id,
|
|
46
|
+
giveToCustomer: mergeSchemas(processedWithCustomerWithPod(), objectWithShopId(), objectWithNetworkId()),
|
|
47
|
+
},
|
|
48
|
+
required: ['_id', 'giveToCustomer'],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const giveToDriverEvent = () => ({
|
|
53
|
+
title: 'give to driver',
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
_id: expedition().properties._id,
|
|
57
|
+
giveToDriver: mergeSchemas(processedWithDriver(), objectWithShopId(), objectWithNetworkId()),
|
|
58
|
+
},
|
|
59
|
+
required: ['_id', 'giveToDriver'],
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const expirationReminderEvent = () => ({
|
|
64
|
+
title: 'expiration reminder',
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
_id: expedition().properties._id,
|
|
68
|
+
expirationReminder: mergeSchemas(objectWithExpirationDate(), objectWithShopId(), objectWithNetworkId()),
|
|
69
|
+
},
|
|
70
|
+
required: ['_id', 'expirationReminder'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const expiredEvent = () => ({
|
|
75
|
+
title: 'expired',
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
_id: expedition().properties._id,
|
|
79
|
+
expired: mergeSchemas(objectWithExpirationDate(), objectWithShopId(), objectWithNetworkId()),
|
|
80
|
+
},
|
|
81
|
+
required: ['_id', 'expired'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const priceEvent = () => ({
|
|
86
|
+
title: 'price',
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {
|
|
89
|
+
_id: expedition().properties._id,
|
|
90
|
+
price: mergeSchemas(objectWithShopId(), objectWithNetworkId(), {
|
|
91
|
+
properties: {
|
|
92
|
+
total: expedition().properties.derivation.properties.totalPrice,
|
|
93
|
+
},
|
|
94
|
+
required: ['total'],
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
required: ['_id', 'price'],
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const upsertShopEvent = () => ({
|
|
102
|
+
title: 'upsert shop',
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: { shop: shop() },
|
|
105
|
+
required: ['shop'],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const upsertNetworkEvent = () => ({
|
|
110
|
+
title: 'upsert network',
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: { network: network() },
|
|
113
|
+
required: ['network'],
|
|
114
|
+
additionalProperties: false,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
receiveFromDriverEvent,
|
|
119
|
+
receiveFromCustomerEvent,
|
|
120
|
+
giveToCustomerEvent,
|
|
121
|
+
giveToDriverEvent,
|
|
122
|
+
expirationReminderEvent,
|
|
123
|
+
expiredEvent,
|
|
124
|
+
priceEvent,
|
|
125
|
+
upsertShopEvent,
|
|
126
|
+
upsertNetworkEvent,
|
|
127
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { uuid, datetime, datetimeRange, findRequest, findResponse, mergeSchemas } = require('@gls_spain/common-json-schemas');
|
|
2
|
+
const {
|
|
3
|
+
receiveFromDriverEvent,
|
|
4
|
+
receiveFromCustomerEvent,
|
|
5
|
+
giveToCustomerEvent,
|
|
6
|
+
giveToDriverEvent,
|
|
7
|
+
expirationReminderEvent,
|
|
8
|
+
expiredEvent,
|
|
9
|
+
priceEvent,
|
|
10
|
+
upsertShopEvent,
|
|
11
|
+
upsertNetworkEvent,
|
|
12
|
+
} = require('./integration-events');
|
|
13
|
+
|
|
14
|
+
const job = () => ({
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
_id: uuid(),
|
|
18
|
+
createdAt: datetime(),
|
|
19
|
+
processAt: datetime(),
|
|
20
|
+
status: { type: 'string', enum: ['pending', 'completed', 'failed'] },
|
|
21
|
+
results: {
|
|
22
|
+
type: 'array',
|
|
23
|
+
items: {
|
|
24
|
+
oneOf: [
|
|
25
|
+
{
|
|
26
|
+
title: 'success',
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
at: datetime(),
|
|
30
|
+
success: { type: 'string' },
|
|
31
|
+
},
|
|
32
|
+
required: ['at', 'success'],
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: 'error',
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
at: datetime(),
|
|
40
|
+
error: { type: 'string' },
|
|
41
|
+
},
|
|
42
|
+
required: ['at', 'error'],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
description: 'the result of each try to process the job',
|
|
48
|
+
},
|
|
49
|
+
payload: { type: 'object' },
|
|
50
|
+
},
|
|
51
|
+
required: ['_id', 'createdAt', 'processAt', 'status', 'results', 'payload'],
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const consistencyJob = () =>
|
|
56
|
+
mergeSchemas(job(), {
|
|
57
|
+
properties: {
|
|
58
|
+
payload: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
collection: { type: 'string' },
|
|
62
|
+
_id: uuid(),
|
|
63
|
+
},
|
|
64
|
+
required: ['collection', '_id'],
|
|
65
|
+
additionalProperties: true,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const expeditionJob = () =>
|
|
71
|
+
mergeSchemas(job(), {
|
|
72
|
+
properties: {
|
|
73
|
+
payload: {
|
|
74
|
+
oneOf: [
|
|
75
|
+
receiveFromDriverEvent(),
|
|
76
|
+
receiveFromCustomerEvent(),
|
|
77
|
+
giveToCustomerEvent(),
|
|
78
|
+
giveToDriverEvent(),
|
|
79
|
+
expirationReminderEvent(),
|
|
80
|
+
expiredEvent(),
|
|
81
|
+
priceEvent(),
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const shopJob = () =>
|
|
88
|
+
mergeSchemas(job(), {
|
|
89
|
+
properties: { payload: upsertShopEvent() },
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const networkJob = () =>
|
|
93
|
+
mergeSchemas(job(), {
|
|
94
|
+
properties: { payload: upsertNetworkEvent() },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const findByStatusAndProcessAt = () => ({
|
|
98
|
+
title: 'find by status and processAt',
|
|
99
|
+
type: 'object',
|
|
100
|
+
properties: {
|
|
101
|
+
status: job().properties.status,
|
|
102
|
+
processAtRange: datetimeRange(),
|
|
103
|
+
},
|
|
104
|
+
required: ['status', 'processAtRange'],
|
|
105
|
+
additionalProperties: false,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const findJobsRequest = () => findRequest(findByStatusAndProcessAt());
|
|
109
|
+
|
|
110
|
+
const findExpeditionJobsResponse = () => findResponse(expeditionJob());
|
|
111
|
+
|
|
112
|
+
const findShopsJobsResponse = () => findResponse(shopJob());
|
|
113
|
+
|
|
114
|
+
const findNetworksJobsResponse = () => findResponse(networkJob());
|
|
115
|
+
|
|
116
|
+
module.exports = {
|
|
117
|
+
job,
|
|
118
|
+
consistencyJob,
|
|
119
|
+
expeditionJob,
|
|
120
|
+
findJobsRequest,
|
|
121
|
+
findExpeditionJobsResponse,
|
|
122
|
+
findShopsJobsResponse,
|
|
123
|
+
findNetworksJobsResponse,
|
|
124
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { superAdmin, networkAdmin, shopUser } = require('./users');
|
|
2
|
+
const { network } = require('./networks');
|
|
3
|
+
const { shop } = require('./shops');
|
|
4
|
+
|
|
5
|
+
const loginResponse = () => ({
|
|
6
|
+
oneOf: [
|
|
7
|
+
{
|
|
8
|
+
title: 'super admin',
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: { user: superAdmin() },
|
|
11
|
+
require: ['user'],
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
title: 'network admin',
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
user: networkAdmin(),
|
|
19
|
+
network: network(),
|
|
20
|
+
},
|
|
21
|
+
require: ['user', 'network'],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: 'shop user',
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
user: shopUser(),
|
|
29
|
+
network: network(),
|
|
30
|
+
shop: shop(),
|
|
31
|
+
},
|
|
32
|
+
require: ['user', 'network', 'shop'],
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
module.exports = { loginResponse };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const {
|
|
2
|
+
uuid,
|
|
3
|
+
objectWithUuid,
|
|
4
|
+
datetime,
|
|
5
|
+
createRequest,
|
|
6
|
+
createResponse,
|
|
7
|
+
findRequest,
|
|
8
|
+
findResponse,
|
|
9
|
+
updateRequest,
|
|
10
|
+
updateResponse,
|
|
11
|
+
deleteRequest,
|
|
12
|
+
deleteResponse,
|
|
13
|
+
pickProperties,
|
|
14
|
+
} = require('@gls_spain/common-json-schemas');
|
|
15
|
+
const { findAll, findById, findByName, objectWithUuidAndName, tags, contact, fiscal } = require('./common');
|
|
16
|
+
const { defaults, derivationSettings, expirationSettings } = require('./defaults');
|
|
17
|
+
|
|
18
|
+
const network = () => ({
|
|
19
|
+
title: 'network',
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
_id: uuid(),
|
|
23
|
+
createdAt: datetime(),
|
|
24
|
+
updatedAt: datetime(),
|
|
25
|
+
deletable: { type: 'boolean' },
|
|
26
|
+
defaults: defaults(),
|
|
27
|
+
name: { type: 'string' },
|
|
28
|
+
integrations: { type: 'array', items: { type: 'string', enum: ['gls'] }, uniqueItems: true },
|
|
29
|
+
contacts: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
items: contact(),
|
|
32
|
+
},
|
|
33
|
+
fiscal: fiscal(),
|
|
34
|
+
derivationSettings: derivationSettings(),
|
|
35
|
+
expirationSettings: expirationSettings(),
|
|
36
|
+
},
|
|
37
|
+
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'defaults', 'name', 'integrations', 'contacts', 'fiscal'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const objectWithNetworkId = () => ({
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: { network: objectWithUuid() },
|
|
44
|
+
required: ['network'],
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const createNetworkRequest = () =>
|
|
49
|
+
createRequest({
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
...pickProperties(network(), [
|
|
53
|
+
'_id',
|
|
54
|
+
'createdAt',
|
|
55
|
+
'name',
|
|
56
|
+
'integrations',
|
|
57
|
+
'contacts',
|
|
58
|
+
'fiscal',
|
|
59
|
+
'derivationSettings',
|
|
60
|
+
'expirationSettings',
|
|
61
|
+
]),
|
|
62
|
+
tags: tags(),
|
|
63
|
+
},
|
|
64
|
+
required: ['name', 'fiscal'],
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const createNetworkResponse = () => createResponse(network());
|
|
69
|
+
|
|
70
|
+
const listNetworksNamesResponse = () => ({
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: { found: { type: 'array', items: objectWithUuidAndName() } },
|
|
73
|
+
required: ['found'],
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const findNetworksRequest = () => findRequest({ oneOf: [findAll(), findById(), findByName()] });
|
|
78
|
+
|
|
79
|
+
const findNetworksResponse = () => findResponse(network());
|
|
80
|
+
|
|
81
|
+
const updateNetworkRequest = () =>
|
|
82
|
+
updateRequest(findById(), {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: { ...pickProperties(network(), ['name', 'contacts', 'fiscal'], ['derivationSettings', 'expirationSettings']) },
|
|
85
|
+
minProperties: 1,
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const updateNetworkResponse = () => updateResponse(network());
|
|
90
|
+
|
|
91
|
+
const deleteNetworkRequest = () => deleteRequest(findById());
|
|
92
|
+
|
|
93
|
+
const deleteNetworkResponse = () => deleteResponse(network());
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
network,
|
|
97
|
+
objectWithNetworkId,
|
|
98
|
+
createNetworkRequest,
|
|
99
|
+
createNetworkResponse,
|
|
100
|
+
listNetworksNamesResponse,
|
|
101
|
+
findNetworksRequest,
|
|
102
|
+
findNetworksResponse,
|
|
103
|
+
updateNetworkRequest,
|
|
104
|
+
updateNetworkResponse,
|
|
105
|
+
deleteNetworkRequest,
|
|
106
|
+
deleteNetworkResponse,
|
|
107
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { uuid, objectWithUuid, datetime, findRequest, findResponse, mergeSchemas } = require('@gls_spain/common-json-schemas');
|
|
2
|
+
const { findById } = require('./common');
|
|
3
|
+
const { objectWithExpeditionId } = require('./expeditions');
|
|
4
|
+
|
|
5
|
+
const pod = () => ({
|
|
6
|
+
title: 'pod',
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
_id: uuid(),
|
|
10
|
+
createdAt: datetime(),
|
|
11
|
+
updatedAt: datetime(),
|
|
12
|
+
deletable: { type: 'boolean' },
|
|
13
|
+
network: objectWithUuid(),
|
|
14
|
+
shop: objectWithUuid(),
|
|
15
|
+
expeditions: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: { _ids: { type: 'array', items: uuid(), uniqueItems: true } },
|
|
18
|
+
required: ['_ids'],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
image: { type: 'string', contentMediaType: 'image/jpg', contentEncoding: 'base64' },
|
|
22
|
+
},
|
|
23
|
+
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'network', 'shop', 'expeditions', 'image'],
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const findByExpedition = () => mergeSchemas(objectWithExpeditionId(), { title: 'find by expedition' });
|
|
28
|
+
|
|
29
|
+
const findPodsRequest = () => findRequest({ oneOf: [findById(), findByExpedition()] });
|
|
30
|
+
|
|
31
|
+
const findPodsResponse = () => findResponse(pod());
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
pod,
|
|
35
|
+
findPodsRequest,
|
|
36
|
+
findPodsResponse,
|
|
37
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
const {
|
|
2
|
+
uuid,
|
|
3
|
+
datetime,
|
|
4
|
+
datetimeRange,
|
|
5
|
+
email,
|
|
6
|
+
phone,
|
|
7
|
+
money,
|
|
8
|
+
objectWithUuid,
|
|
9
|
+
createRequest,
|
|
10
|
+
createResponse,
|
|
11
|
+
findRequest,
|
|
12
|
+
findResponse,
|
|
13
|
+
updateRequest,
|
|
14
|
+
updateResponse,
|
|
15
|
+
deleteRequest,
|
|
16
|
+
deleteResponse,
|
|
17
|
+
pickProperties,
|
|
18
|
+
} = require('@gls_spain/common-json-schemas');
|
|
19
|
+
const { findAll, findById, findByName, objectWithUuidAndName, tags } = require('./common');
|
|
20
|
+
const { zone } = require('./zones');
|
|
21
|
+
|
|
22
|
+
const representative = () => ({
|
|
23
|
+
title: 'representative',
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
_id: uuid(),
|
|
27
|
+
createdAt: datetime(),
|
|
28
|
+
updatedAt: datetime(),
|
|
29
|
+
deletable: { type: 'boolean' },
|
|
30
|
+
name: { type: 'string' },
|
|
31
|
+
emails: { type: 'array', items: email(), uniqueItems: true },
|
|
32
|
+
phones: { type: 'array', items: phone(), uniqueItems: true },
|
|
33
|
+
nif: { type: 'string' },
|
|
34
|
+
zones: {
|
|
35
|
+
type: 'array',
|
|
36
|
+
items: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: { ...pickProperties(zone(), ['_id', 'name']) },
|
|
39
|
+
required: ['_id', 'name'],
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
},
|
|
42
|
+
uniqueItems: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'name', 'emails', 'phones', 'nif', 'zones'],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const setRepresentativesZones = () => ({
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: objectWithUuid(),
|
|
52
|
+
uniqueItems: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const createRepresentativeRequest = () =>
|
|
56
|
+
createRequest({
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
...pickProperties(representative(), ['_id', 'createdAt', 'name', 'emails', 'phones', 'nif']),
|
|
60
|
+
zones: setRepresentativesZones(),
|
|
61
|
+
tags: tags(),
|
|
62
|
+
},
|
|
63
|
+
required: ['name', 'nif'],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const createRepresentativeResponse = () => createResponse(representative());
|
|
68
|
+
|
|
69
|
+
const findRepresentativesRequest = () => findRequest({ oneOf: [findAll(), findById(), findByName()] });
|
|
70
|
+
|
|
71
|
+
const findRepresentativesResponse = () => findResponse(representative());
|
|
72
|
+
|
|
73
|
+
const listRepresentativesNamesResponse = () => ({
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: { found: { type: 'array', items: objectWithUuidAndName() } },
|
|
76
|
+
required: ['found'],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const updateRepresentativeRequest = () =>
|
|
81
|
+
updateRequest(
|
|
82
|
+
findById(),
|
|
83
|
+
{
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
zones: setRepresentativesZones(),
|
|
87
|
+
...pickProperties(representative(), ['name', 'emails', 'phones', 'nif']),
|
|
88
|
+
},
|
|
89
|
+
minProperties: 1,
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
zones: setRepresentativesZones(),
|
|
96
|
+
...pickProperties(representative(), ['emails', 'phones']),
|
|
97
|
+
},
|
|
98
|
+
minProperties: 1,
|
|
99
|
+
additionalProperties: false,
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const updateRepresentativeResponse = () => updateResponse(representative());
|
|
104
|
+
|
|
105
|
+
const shopCommissions = () => ({
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
name: { type: 'string' },
|
|
109
|
+
since: datetime(),
|
|
110
|
+
},
|
|
111
|
+
required: ['name', 'since'],
|
|
112
|
+
additionalProperties: false,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const zoneCommissions = () => ({
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
name: { type: 'string' },
|
|
119
|
+
total: money(),
|
|
120
|
+
openedShops: { type: 'array', items: shopCommissions() },
|
|
121
|
+
managedShops: { type: 'array', items: shopCommissions() },
|
|
122
|
+
},
|
|
123
|
+
required: ['name', 'total', 'openedShops', 'managedShops'],
|
|
124
|
+
additionalProperties: false,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const getRepresentativeCommissionsRequest = () => ({
|
|
128
|
+
type: 'object',
|
|
129
|
+
properties: {
|
|
130
|
+
get: {
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
representative: objectWithUuid(),
|
|
134
|
+
datetimeRange: datetimeRange(),
|
|
135
|
+
},
|
|
136
|
+
required: ['representative', 'datetimeRange'],
|
|
137
|
+
additionalProperties: false,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
required: ['get'],
|
|
141
|
+
additionalProperties: false,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const getRepresentativeCommissionsResponse = () => ({
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: {
|
|
147
|
+
get: {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
total: money(),
|
|
151
|
+
zones: { type: 'array', items: zoneCommissions() },
|
|
152
|
+
},
|
|
153
|
+
required: ['total', 'zones'],
|
|
154
|
+
additionalProperties: false,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
required: ['get'],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const deleteRepresentativeRequest = () => deleteRequest(findById());
|
|
162
|
+
|
|
163
|
+
const deleteRepresentativeResponse = () => deleteResponse(representative());
|
|
164
|
+
|
|
165
|
+
module.exports = {
|
|
166
|
+
representative,
|
|
167
|
+
createRepresentativeRequest,
|
|
168
|
+
createRepresentativeResponse,
|
|
169
|
+
findRepresentativesRequest,
|
|
170
|
+
findRepresentativesResponse,
|
|
171
|
+
listRepresentativesNamesResponse,
|
|
172
|
+
updateRepresentativeRequest,
|
|
173
|
+
updateRepresentativeResponse,
|
|
174
|
+
getRepresentativeCommissionsRequest,
|
|
175
|
+
getRepresentativeCommissionsResponse,
|
|
176
|
+
deleteRepresentativeRequest,
|
|
177
|
+
deleteRepresentativeResponse,
|
|
178
|
+
};
|