@gls_spain/gps-common 32.4.0 → 33.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ const {
2
+ uuid,
3
+ datetime,
4
+ email,
5
+ phone,
6
+ money,
7
+ createRequest,
8
+ createResponse,
9
+ findRequest,
10
+ findResponse,
11
+ mergeSchemas,
12
+ pickProperties,
13
+ } = require('@gls_spain/common-json-schemas');
14
+ const { country, findAll, findById } = require('./common');
15
+ const { address } = require('./common');
16
+ const { saleSize, salesSettings } = require('./defaults');
17
+ const { network, objectWithNetworkId } = require('./networks');
18
+ const { shop, objectWithShopId } = require('./shops');
19
+
20
+ const sale = () => ({
21
+ title: 'sale',
22
+ type: 'object',
23
+ properties: {
24
+ _id: uuid(),
25
+ createdAt: datetime(),
26
+ updatedAt: datetime(),
27
+ deletable: { type: 'boolean' },
28
+ network: {
29
+ type: 'object',
30
+ properties: { ...pickProperties(network(), ['_id', 'name']) },
31
+ required: ['_id', 'name'],
32
+ additionalProperties: false,
33
+ },
34
+ shop: {
35
+ type: 'object',
36
+ properties: { ...pickProperties(shop(), ['_id', 'name']) },
37
+ required: ['_id', 'name'],
38
+ additionalProperties: false,
39
+ },
40
+ status: {
41
+ type: 'object',
42
+ properties: {
43
+ code: { type: 'string', enum: ['pending', 'paid', 'failed'] },
44
+ },
45
+ required: ['code'],
46
+ additionalProperties: false,
47
+ },
48
+ size: saleSize(),
49
+ price: money(),
50
+ settings: mergeSchemas(salesSettings(), network().properties.salesSettings, {
51
+ description: 'a copy of both the defaults sale settings and the network sale settings as they were when the sale was created',
52
+ }),
53
+ destination: {
54
+ type: 'object',
55
+ properties: {
56
+ name: { type: 'string', trim: true },
57
+ address: address(),
58
+ emails: { type: 'array', items: email(), uniqueItems: true },
59
+ phones: { type: 'array', items: phone(), uniqueItems: true },
60
+ notes: { type: 'string', trim: true },
61
+ },
62
+ required: ['name', 'address', 'emails', 'phones'],
63
+ additionalProperties: false,
64
+ },
65
+ sender: {
66
+ type: 'object',
67
+ properties: {
68
+ name: { type: 'string', trim: true },
69
+ nif: { type: 'string', trim: true },
70
+ address: address(),
71
+ emails: { type: 'array', items: email(), uniqueItems: true },
72
+ phones: { type: 'array', items: phone(), uniqueItems: true },
73
+ fiscal: {
74
+ type: 'object',
75
+ properties: {
76
+ name: { type: 'string', trim: true },
77
+ nif: { type: 'string', trim: true },
78
+ address: address(),
79
+ emails: { type: 'array', items: email(), uniqueItems: true },
80
+ phones: { type: 'array', items: phone(), uniqueItems: true },
81
+ },
82
+ required: ['name', 'nif', 'address', 'emails', 'phones'],
83
+ additionalProperties: false,
84
+ },
85
+ notes: { type: 'string', trim: true },
86
+ reference: { type: 'string', trim: true },
87
+ },
88
+ required: ['name', 'nif', 'address', 'emails', 'phones', 'fiscal'],
89
+ additionalProperties: false,
90
+ },
91
+ },
92
+ required: [
93
+ '_id',
94
+ 'createdAt',
95
+ 'updatedAt',
96
+ 'deletable',
97
+ 'network',
98
+ 'shop',
99
+ 'status',
100
+ 'size',
101
+ 'price',
102
+ 'settings',
103
+ 'destination',
104
+ 'sender',
105
+ ],
106
+ additionalProperties: false,
107
+ });
108
+
109
+ const createSaleRequest = () =>
110
+ createRequest({
111
+ type: 'object',
112
+ properties: {
113
+ ...pickProperties(sale(), ['_id', 'createdAt', 'size', 'destination', 'sender']),
114
+ },
115
+ required: ['shop', 'size', 'destination', 'sender'],
116
+ additionalProperties: false,
117
+ });
118
+
119
+ const createSaleResponse = () => createResponse(sale());
120
+
121
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
122
+
123
+ const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
124
+
125
+ const findSalesSuperAdminRequest = () => findRequest({ oneOf: [findAll(), findByNetwork(), findByShop(), findById()] });
126
+
127
+ const findSalesNetworkAdminRequest = () => findRequest({ oneOf: [findAll(), findByShop(), findById()] });
128
+
129
+ const findSalesShopUserRequest = () => findRequest({ oneOf: [findAll(), findById()] });
130
+
131
+ const findSalesResponse = () => findResponse(sale());
132
+
133
+ const checkSalePriceRequest = () => ({
134
+ type: 'object',
135
+ properties: {
136
+ size: saleSize(),
137
+ country: country(),
138
+ postalCode: { type: 'string', trim: true },
139
+ },
140
+ required: ['size', 'country', 'postalCode'],
141
+ additionalProperties: false,
142
+ });
143
+
144
+ const checkSalePriceResponse = () => ({
145
+ type: 'object',
146
+ properties: {
147
+ price: money(),
148
+ },
149
+ required: ['price'],
150
+ additionalProperties: false,
151
+ });
152
+
153
+ module.exports = {
154
+ sale,
155
+ createSaleRequest,
156
+ createSaleResponse,
157
+ findSalesSuperAdminRequest,
158
+ findSalesNetworkAdminRequest,
159
+ findSalesShopUserRequest,
160
+ findSalesResponse,
161
+ checkSalePriceRequest,
162
+ checkSalePriceResponse,
163
+ };
@@ -127,6 +127,7 @@ const shop = () => ({
127
127
  createdAt: datetime(),
128
128
  updatedAt: datetime(),
129
129
  deletable: { type: 'boolean' },
130
+ readonly: { type: 'boolean', description: 'readonly shops do not allow updates or adding expeditions to them' },
130
131
  international: {
131
132
  type: 'object',
132
133
  properties: {
@@ -206,6 +207,7 @@ const shop = () => ({
206
207
  'createdAt',
207
208
  'updatedAt',
208
209
  'deletable',
210
+ 'readonly',
209
211
  'international',
210
212
  'defaults',
211
213
  'network',
@@ -247,7 +249,7 @@ const createShopRequest = () =>
247
249
  createRequest({
248
250
  type: 'object',
249
251
  properties: {
250
- ...pickProperties(shop(), ['_id', 'createdAt']),
252
+ ...pickProperties(shop(), ['_id', 'createdAt', 'readonly']),
251
253
  network: objectWithUuid(),
252
254
  zone: objectWithUuid(),
253
255
  openingRepresentative: setShopRepresentative(),
package/schemas/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const { addMetadata, errorResponse: sourceErrorResponse } = require('@gls_spain/common-json-schemas');
2
- const { initRequest, initResponse } = require('./definitions/init');
3
2
  const { getDefaultsResponse, updateDefaultsRequest, updateDefaultsResponse } = require('./definitions/defaults');
4
3
  const { getCountersResponse } = require('./definitions/counters');
5
4
  const { loginResponse: sourceLoginResponse } = require('./definitions/login');
@@ -104,6 +103,16 @@ const {
104
103
  } = require('./definitions/zones');
105
104
  const { findIntegrationsRequest, findIntegrationsResponse } = require('./definitions/integrations');
106
105
  const { findHistoricRecordsRequest, findHistoricRecordsResponse } = require('./definitions/historic-records');
106
+ const {
107
+ createSaleRequest,
108
+ createSaleResponse,
109
+ findSalesSuperAdminRequest,
110
+ findSalesNetworkAdminRequest,
111
+ findSalesShopUserRequest,
112
+ findSalesResponse,
113
+ checkSalePriceRequest,
114
+ checkSalePriceResponse,
115
+ } = require('./definitions/sales');
107
116
 
108
117
  function request(schema, $id) {
109
118
  return addMetadata(schema, $id);
@@ -115,8 +124,6 @@ function response(schema, $id) {
115
124
 
116
125
  const errorResponse = addMetadata(sourceErrorResponse(), 'errorResponse');
117
126
 
118
- const configInitRequest = request(initRequest(), 'configInitRequest');
119
- const configInitResponse = response(initResponse(), 'configInitResponse');
120
127
  const configDefaultsGetResponse = response(getDefaultsResponse(), 'configDefaultsGetResponse');
121
128
  const configDefaultsUpdateRequest = request(updateDefaultsRequest(), 'configDefaultsUpdateRequest');
122
129
  const configDefaultsUpdateResponse = response(updateDefaultsResponse(), 'configDefaultsUpdateResponse');
@@ -230,11 +237,18 @@ const integrationsFindResponse = response(findIntegrationsResponse(), 'integrati
230
237
  const historicRecordsFindRequest = request(findHistoricRecordsRequest(), 'historicRecordsFindRequest');
231
238
  const historicRecordsFindResponse = response(findHistoricRecordsResponse(), 'historicRecordsFindResponse');
232
239
 
240
+ const salesCreateRequest = request(createSaleRequest(), 'salesCreateRequest');
241
+ const salesCreateResponse = response(createSaleResponse(), 'salesCreateResponse');
242
+ const salesFindSuperAdminRequest = request(findSalesSuperAdminRequest(), 'salesFindSuperAdminRequest');
243
+ const salesFindNetworkAdminRequest = request(findSalesNetworkAdminRequest(), 'salesFindNetworkAdminRequest');
244
+ const salesFindShopUserRequest = request(findSalesShopUserRequest(), 'salesFindShopUserRequest');
245
+ const salesFindResponse = response(findSalesResponse(), 'salesFindResponse');
246
+ const salesCheckPriceRequest = request(checkSalePriceRequest(), 'salesCheckPriceRequest');
247
+ const salesCheckPriceResponse = response(checkSalePriceResponse(), 'salesCheckPriceResponse');
248
+
233
249
  module.exports = {
234
250
  errorResponse,
235
251
 
236
- configInitRequest,
237
- configInitResponse,
238
252
  configDefaultsGetResponse,
239
253
  configDefaultsUpdateRequest,
240
254
  configDefaultsUpdateResponse,
@@ -344,4 +358,13 @@ module.exports = {
344
358
 
345
359
  historicRecordsFindRequest,
346
360
  historicRecordsFindResponse,
361
+
362
+ salesCreateRequest,
363
+ salesCreateResponse,
364
+ salesFindSuperAdminRequest,
365
+ salesFindNetworkAdminRequest,
366
+ salesFindShopUserRequest,
367
+ salesFindResponse,
368
+ salesCheckPriceRequest,
369
+ salesCheckPriceResponse,
347
370
  };
@@ -1,50 +0,0 @@
1
- const { password, pickProperties } = require('@gls_spain/common-json-schemas');
2
- const { superAdmin } = require('./users');
3
- const { defaults } = require('./defaults');
4
- const { counters } = require('./counters');
5
-
6
- const initRequest = () => ({
7
- type: 'object',
8
- properties: {
9
- superAdmin: {
10
- type: 'object',
11
- properties: {
12
- username: superAdmin().properties.username,
13
- password: password(),
14
- },
15
- required: ['username', 'password'],
16
- additionalProperties: false,
17
- },
18
- defaults: {
19
- type: 'object',
20
- properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
21
- required: ['derivationSettings', 'expirationSettings'],
22
- additionalProperties: false,
23
- },
24
- counters: {
25
- type: 'object',
26
- properties: { ...pickProperties(counters(), ['shops']) },
27
- required: ['shops'],
28
- additionalProperties: false,
29
- },
30
- },
31
- required: ['superAdmin', 'defaults', 'counters'],
32
- additionalProperties: false,
33
- });
34
-
35
- const initResponse = () => ({
36
- type: 'object',
37
- properties: {
38
- superAdmin: superAdmin(),
39
- defaults: defaults(),
40
- counters: counters(),
41
- indexes: { type: 'array', items: { type: 'string' } },
42
- },
43
- required: ['superAdmin', 'defaults', 'counters', 'indexes'],
44
- additionalProperties: false,
45
- });
46
-
47
- module.exports = {
48
- initRequest,
49
- initResponse,
50
- };