@autofleet/sheilta 1.2.1 → 1.2.2

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.
@@ -1,11 +1,13 @@
1
1
  declare type OrderItem = string | [string, string];
2
2
  declare type SequelizeOrder = string | OrderItem[];
3
- declare const formatPayload: ({ order, page, perPage, include, }: {
3
+ declare const formatPayload: ({ order, page, perPage, include, query, }: {
4
4
  order: any;
5
5
  page?: number;
6
6
  perPage?: number;
7
7
  include?: any[];
8
+ query?: {};
8
9
  }, model?: any) => {
10
+ query: {};
9
11
  order: SequelizeOrder[];
10
12
  page: any;
11
13
  perPage: any;
@@ -6,7 +6,7 @@ const formatOrder = ({ order = [], associationModels = [], }) => (order.length =
6
6
  order.map((o) => {
7
7
  const formattedOrder = [utils_1.extractAttributeNameFromOrder(o, associationModels)];
8
8
  const isOrderDescOrder = utils_1.isOrderDesc(o);
9
- const isOrderAssociation = utils_1.isOrderByAssociation(isOrderDescOrder
9
+ const isOrderAssociation = utils_1.isAttributeByAssociation(isOrderDescOrder
10
10
  ? o.split(utils_1.ORDER_PREFIX)[1]
11
11
  : o, associationModels);
12
12
  if (isOrderAssociation) {
@@ -20,7 +20,9 @@ const formatOrder = ({ order = [], associationModels = [], }) => (order.length =
20
20
  const formatPage = page => page || utils_1.PAGE_DEFAULT;
21
21
  const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
22
22
  const formatInclude = (include, associationsMap = {}) => include.map(i => associationsMap[i.model]);
23
- const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], }, model) => {
23
+ const formatQuery = (query, associationModels) => Object.keys(query).reduce((acc, queryItemKey) => (Object.assign(Object.assign({}, acc), { [utils_1.isAttributeByAssociation(queryItemKey, associationModels)
24
+ ? utils_1.wrapAttributeWithOperator(queryItemKey) : queryItemKey]: query[queryItemKey] })), {});
25
+ const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, }, model) => {
24
26
  const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
25
27
  const formattedOrder = formatOrder({
26
28
  order,
@@ -29,7 +31,9 @@ const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.P
29
31
  const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
30
32
  const formattedPage = formatPage(page);
31
33
  const formattedPerPage = formatPerPage(perPage);
34
+ const formattedQuery = formatQuery(query, associationModels);
32
35
  return {
36
+ query: formattedQuery,
33
37
  order: formattedOrder,
34
38
  page: formattedPage,
35
39
  perPage: formattedPerPage,
@@ -5,62 +5,99 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const _1 = __importDefault(require("."));
7
7
  describe('formatting test', () => {
8
- it('check order formatting', () => {
9
- const { order } = _1.default({
10
- order: ['startTime', '-endTime'],
8
+ describe('query formatting', () => {
9
+ it('query json field', () => {
10
+ const { query } = _1.default({
11
+ order: [],
12
+ query: {
13
+ 'json.field': {
14
+ $gt: 4,
15
+ },
16
+ },
17
+ }, {
18
+ rawAttributes: {
19
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
20
+ },
21
+ });
22
+ expect(JSON.stringify(query)).toBe(JSON.stringify({ 'json.field': { $gt: 4 } }));
11
23
  });
12
- expect(JSON.stringify(order)).toBe(JSON.stringify([['startTime'], ['endTime', 'DESC']]));
13
- });
14
- it('check order formatting', () => {
15
- const { order } = _1.default({
16
- order: ['startTime', 'endTime'],
24
+ it('query included model field', () => {
25
+ const { query } = _1.default({
26
+ order: [],
27
+ query: {
28
+ 'status.field': {
29
+ $gt: 4,
30
+ },
31
+ },
32
+ }, {
33
+ rawAttributes: {
34
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
35
+ },
36
+ associations: {
37
+ status: {},
38
+ },
39
+ });
40
+ expect(JSON.stringify(query)).toBe(JSON.stringify({ '$status.field$': { $gt: 4 } }));
17
41
  });
18
- expect(JSON.stringify(order)).toBe(JSON.stringify([['startTime'], ['endTime']]));
19
42
  });
20
- it('check order formatting - by included model', () => {
21
- const { order } = _1.default({
22
- order: ['status.name'],
23
- }, {
24
- rawAttributes: {
25
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
26
- },
27
- associations: {
28
- status: {},
29
- },
43
+ describe('order formatting', () => {
44
+ it('simple check', () => {
45
+ const { order } = _1.default({
46
+ order: ['startTime', '-endTime'],
47
+ });
48
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['startTime'], ['endTime', 'DESC']]));
30
49
  });
31
- expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name']]));
32
- });
33
- it('check order formatting - by included model descending', () => {
34
- const { order } = _1.default({
35
- order: ['-status.name'],
36
- }, {
37
- rawAttributes: {
38
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
39
- },
40
- associations: {
41
- status: {},
42
- },
50
+ it('simple check asc', () => {
51
+ const { order } = _1.default({
52
+ order: ['startTime', 'endTime'],
53
+ });
54
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['startTime'], ['endTime']]));
43
55
  });
44
- expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name', 'DESC']]));
45
- });
46
- it('check order formatting - by json field', () => {
47
- const { order } = _1.default({
48
- order: ['status.name'],
49
- }, {
50
- rawAttributes: {
51
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
52
- },
56
+ it('by included model', () => {
57
+ const { order } = _1.default({
58
+ order: ['status.name'],
59
+ }, {
60
+ rawAttributes: {
61
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
62
+ },
63
+ associations: {
64
+ status: {},
65
+ },
66
+ });
67
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name']]));
53
68
  });
54
- expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name']]));
55
- });
56
- it('check order formatting - by json field descending', () => {
57
- const { order } = _1.default({
58
- order: ['-status.name'],
59
- }, {
60
- rawAttributes: {
61
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
62
- },
69
+ it('by included model descending', () => {
70
+ const { order } = _1.default({
71
+ order: ['-status.name'],
72
+ }, {
73
+ rawAttributes: {
74
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
75
+ },
76
+ associations: {
77
+ status: {},
78
+ },
79
+ });
80
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name', 'DESC']]));
81
+ });
82
+ it('by json field', () => {
83
+ const { order } = _1.default({
84
+ order: ['status.name'],
85
+ }, {
86
+ rawAttributes: {
87
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
88
+ },
89
+ });
90
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name']]));
91
+ });
92
+ it('by json field descending', () => {
93
+ const { order } = _1.default({
94
+ order: ['-status.name'],
95
+ }, {
96
+ rawAttributes: {
97
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
98
+ },
99
+ });
100
+ expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name', 'DESC']]));
63
101
  });
64
- expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name', 'DESC']]));
65
102
  });
66
103
  });
@@ -42,13 +42,15 @@ exports.newQueryValidationMiddleware = (inner = 'body') => model => (req, res, n
42
42
  }
43
43
  });
44
44
  exports.newQueryFormatMiddleware = (inner = 'body') => model => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
45
- const { order, page, perPage, include, } = req[inner];
46
- const { order: formattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, } = formatter_1.default({
45
+ const { order, page, perPage, include, query, } = req[inner];
46
+ const { query: formattedQuery, order: formattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, } = formatter_1.default({
47
+ query,
47
48
  order,
48
49
  page,
49
50
  perPage,
50
51
  include,
51
52
  }, model);
53
+ req[inner].query = formattedQuery;
52
54
  req[inner].order = formattedOrder;
53
55
  req[inner].page = formattedPage;
54
56
  req[inner].perPage = formattedPerPage;
package/lib/utils.d.ts CHANGED
@@ -5,7 +5,8 @@ export declare const PAGE_DEFAULT = 1;
5
5
  export declare const PER_PAGE_MAX_LIMIT = 100;
6
6
  export declare const PER_PAGE_MIN_LIMIT = 1;
7
7
  export declare const PAGE_MIN = 1;
8
- export declare const isOrderByAssociation: (attributeName: any, associatedModels: any) => boolean;
8
+ export declare const wrapAttributeWithOperator: (attribute: any) => string;
9
+ export declare const isAttributeByAssociation: (attributeName: any, associatedModels: any) => boolean;
9
10
  export declare const extractAttributeNameFromOrder: (order: any, associationModels: any) => string;
10
11
  export declare const isOrderDesc: (order: any) => boolean;
11
12
  export declare const throwBadRequestError: (message: string) => never;
package/lib/utils.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractAssociatedAttributeNameFromOrder = exports.throwBadRequestError = exports.isOrderDesc = exports.extractAttributeNameFromOrder = exports.isOrderByAssociation = exports.PAGE_MIN = exports.PER_PAGE_MIN_LIMIT = exports.PER_PAGE_MAX_LIMIT = exports.PAGE_DEFAULT = exports.PER_PAGE_DEFAULT = exports.ASSOCIATION_PREFIX = exports.ORDER_PREFIX = void 0;
3
+ exports.extractAssociatedAttributeNameFromOrder = exports.throwBadRequestError = exports.isOrderDesc = exports.extractAttributeNameFromOrder = exports.isAttributeByAssociation = exports.wrapAttributeWithOperator = exports.PAGE_MIN = exports.PER_PAGE_MIN_LIMIT = exports.PER_PAGE_MAX_LIMIT = exports.PAGE_DEFAULT = exports.PER_PAGE_DEFAULT = exports.ASSOCIATION_PREFIX = exports.ORDER_PREFIX = void 0;
4
4
  const errors_1 = require("@autofleet/errors");
5
+ const operators_1 = require("./operators");
5
6
  exports.ORDER_PREFIX = '-';
6
7
  exports.ASSOCIATION_PREFIX = '.';
7
8
  exports.PER_PAGE_DEFAULT = 20;
@@ -9,7 +10,8 @@ exports.PAGE_DEFAULT = 1;
9
10
  exports.PER_PAGE_MAX_LIMIT = 100;
10
11
  exports.PER_PAGE_MIN_LIMIT = 1;
11
12
  exports.PAGE_MIN = 1;
12
- exports.isOrderByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
13
+ exports.wrapAttributeWithOperator = attribute => `${operators_1.OPERATOR_PREFIX}${attribute}${operators_1.OPERATOR_PREFIX}`;
14
+ exports.isAttributeByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
13
15
  && associatedModels.includes(attributeName.split(exports.ASSOCIATION_PREFIX)[0]);
14
16
  exports.extractAttributeNameFromOrder = (order, associationModels) => {
15
17
  let formattedOrder = order;
@@ -17,7 +19,7 @@ exports.extractAttributeNameFromOrder = (order, associationModels) => {
17
19
  // eslint-disable-next-line prefer-destructuring
18
20
  formattedOrder = formattedOrder.split(exports.ORDER_PREFIX)[1];
19
21
  }
20
- if (exports.isOrderByAssociation(formattedOrder, associationModels)) {
22
+ if (exports.isAttributeByAssociation(formattedOrder, associationModels)) {
21
23
  [formattedOrder] = formattedOrder.split(exports.ASSOCIATION_PREFIX);
22
24
  }
23
25
  return formattedOrder;
@@ -8,7 +8,9 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const utils_1 = require("../utils");
9
9
  const operators_1 = require("../operators");
10
10
  const validateOperator = (operator) => operators_1.OPERATORS.includes(operator.split(operators_1.OPERATOR_PREFIX)[1]);
11
- const validateQueryAttribute = (attribute, modelAttributes) => modelAttributes.includes(attribute);
11
+ const validateQueryAttribute = (attribute, modelAttributes = [], associationModels = []) => [...modelAttributes, ...associationModels]
12
+ .includes(attribute.includes(utils_1.ASSOCIATION_PREFIX)
13
+ ? attribute.split(utils_1.ASSOCIATION_PREFIX)[0] : attribute);
12
14
  const validateSingleOrder = (currentOrder, rawAttributes, associationModels) => {
13
15
  const isOrderDescOrder = utils_1.isOrderDesc(currentOrder);
14
16
  if (isOrderDescOrder && currentOrder[0] !== utils_1.ORDER_PREFIX) {
@@ -16,7 +18,7 @@ const validateSingleOrder = (currentOrder, rawAttributes, associationModels) =>
16
18
  }
17
19
  const orderStringWithoutDesc = isOrderDescOrder ?
18
20
  currentOrder.split(utils_1.ORDER_PREFIX)[1] : currentOrder;
19
- const isOrderAssociation = utils_1.isOrderByAssociation(orderStringWithoutDesc, associationModels);
21
+ const isOrderAssociation = utils_1.isAttributeByAssociation(orderStringWithoutDesc, associationModels);
20
22
  let formattedOrderString = utils_1.extractAttributeNameFromOrder(currentOrder, associationModels);
21
23
  if (!isOrderAssociation && formattedOrderString.includes(utils_1.ASSOCIATION_PREFIX)) {
22
24
  [formattedOrderString] = formattedOrderString.split(utils_1.ASSOCIATION_PREFIX);
@@ -36,16 +38,17 @@ const validateOrderAttributes = (order, rawAttributes, associationModels = []) =
36
38
  const validateAttributes = (attributes, rawAttributes) => {
37
39
  attributes.map(a => validateSingleAttribute(a, rawAttributes));
38
40
  };
39
- const validateQueryPayload = (query, rawAttributes) => {
41
+ const validateQueryPayload = (query, rawAttributes, associationModels = []) => {
40
42
  // eslint-disable-next-line array-callback-return
41
43
  Object.keys(query).map((key) => {
42
44
  const value = query[key];
43
45
  if (lodash_1.default.isArray(value)) {
44
46
  if (lodash_1.default.isObject(value[0])) {
45
- value.map(v => validateQueryPayload(v, rawAttributes));
47
+ value.map(v => validateQueryPayload(v, rawAttributes, associationModels));
46
48
  }
47
49
  }
48
- else if (validateOperator(key) || validateQueryAttribute(key, rawAttributes)) {
50
+ else if (validateOperator(key)
51
+ || validateQueryAttribute(key, rawAttributes, associationModels)) {
49
52
  if (lodash_1.default.isObject(value)) {
50
53
  validateQueryPayload(value, rawAttributes);
51
54
  }
@@ -90,7 +93,7 @@ exports.validatePayload = ({ query = {}, order = [], attributes = [], include =
90
93
  validateAttributes(attributes, rawAttributes);
91
94
  }
92
95
  validateOrderAttributes(order, rawAttributes, associationModels);
93
- validateQueryPayload(query, rawAttributes);
96
+ validateQueryPayload(query, rawAttributes, associationModels);
94
97
  if (include.length) {
95
98
  validateIncludePayload(include, model === null || model === void 0 ? void 0 : model.associations);
96
99
  }
@@ -38,94 +38,147 @@ const query = {
38
38
  };
39
39
  const order = ['startTime', '-endTime'];
40
40
  describe('validations test', () => {
41
- it('check query validation', () => {
42
- const payload = _1.validatePayload({ query }, {
43
- rawAttributes: {
44
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
45
- },
41
+ describe('query validation', () => {
42
+ it('check query validation', () => {
43
+ const payload = _1.validatePayload({ query }, {
44
+ rawAttributes: {
45
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
46
+ },
47
+ });
48
+ expect(payload).toBe(true);
46
49
  });
47
- expect(payload).toBe(true);
48
- });
49
- it('check order validation', () => {
50
- const payload = _1.validatePayload({ order }, {
51
- rawAttributes: {
52
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
53
- },
50
+ it('check query by json property field', () => {
51
+ const payload = _1.validatePayload({
52
+ query: {
53
+ 'jsonField.exampleField': {
54
+ $eq: 'a',
55
+ },
56
+ },
57
+ }, {
58
+ rawAttributes: {
59
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', jsonField: {},
60
+ },
61
+ });
62
+ expect(payload).toBe(true);
54
63
  });
55
- expect(payload).toBe(true);
56
- });
57
- it('check order validation - order does not exist', () => {
58
- try {
59
- _1.validatePayload({ order: ['aviv'] }, {
64
+ it('check query by included model field', () => {
65
+ const payload = _1.validatePayload({
66
+ query: {
67
+ 'status.name': {
68
+ $eq: 'a',
69
+ },
70
+ },
71
+ }, {
60
72
  rawAttributes: {
61
73
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
62
74
  },
75
+ associations: {
76
+ status: {},
77
+ },
63
78
  });
64
- }
65
- catch (error) {
66
- expect(error.statusCode).toBe(400);
67
- }
79
+ expect(payload).toBe(true);
80
+ });
81
+ it('check query by non existent field', () => {
82
+ try {
83
+ _1.validatePayload({
84
+ query: {
85
+ nonExistent: {
86
+ $eq: 'a',
87
+ },
88
+ },
89
+ }, {
90
+ rawAttributes: {
91
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
92
+ },
93
+ });
94
+ }
95
+ catch (error) {
96
+ expect(error.statusCode).toBe(400);
97
+ }
98
+ });
68
99
  });
69
- it('check order validation - prefix in the wrong place', () => {
70
- try {
71
- _1.validatePayload({ order: ['startTime-', 'currencySymbol'] }, {
100
+ describe('order validation', () => {
101
+ it('check order validation', () => {
102
+ const payload = _1.validatePayload({ order }, {
72
103
  rawAttributes: {
73
104
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
74
105
  },
75
106
  });
76
- }
77
- catch (error) {
78
- expect(error.statusCode).toBe(400);
79
- }
80
- });
81
- it('check order validation - order by included model', () => {
82
- const payload = _1.validatePayload({ order: ['status.title'] }, {
83
- rawAttributes: {
84
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
85
- },
86
- associations: {
87
- status: {},
88
- },
107
+ expect(payload).toBe(true);
89
108
  });
90
- expect(payload).toBe(true);
91
- });
92
- it('check order validation - order by included model descending', () => {
93
- const payload = _1.validatePayload({ order: ['-status.title'] }, {
94
- rawAttributes: {
95
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
96
- },
97
- associations: {
98
- status: {},
99
- },
109
+ it('order does not exist', () => {
110
+ try {
111
+ _1.validatePayload({ order: ['aviv'] }, {
112
+ rawAttributes: {
113
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
114
+ },
115
+ });
116
+ }
117
+ catch (error) {
118
+ expect(error.statusCode).toBe(400);
119
+ }
100
120
  });
101
- expect(payload).toBe(true);
102
- });
103
- it('check order validation - order by json field', () => {
104
- const payload = _1.validatePayload({ order: ['status.title'] }, {
105
- rawAttributes: {
106
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
107
- },
121
+ it('prefix in the wrong place', () => {
122
+ try {
123
+ _1.validatePayload({ order: ['startTime-', 'currencySymbol'] }, {
124
+ rawAttributes: {
125
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
126
+ },
127
+ });
128
+ }
129
+ catch (error) {
130
+ expect(error.statusCode).toBe(400);
131
+ }
108
132
  });
109
- expect(payload).toBe(true);
110
- });
111
- it('check order validation - order by json field desc', () => {
112
- const payload = _1.validatePayload({ order: ['-status.title'] }, {
113
- rawAttributes: {
114
- startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
115
- },
133
+ it('order by included model', () => {
134
+ const payload = _1.validatePayload({ order: ['status.title'] }, {
135
+ rawAttributes: {
136
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
137
+ },
138
+ associations: {
139
+ status: {},
140
+ },
141
+ });
142
+ expect(payload).toBe(true);
116
143
  });
117
- expect(payload).toBe(true);
118
- });
119
- it('check order validation - try order by json field that doesnt exist', () => {
120
- try {
121
- _1.validatePayload({ order: ['-stas.title'] }, {
144
+ it('order by included model descending', () => {
145
+ const payload = _1.validatePayload({ order: ['-status.title'] }, {
146
+ rawAttributes: {
147
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
148
+ },
149
+ associations: {
150
+ status: {},
151
+ },
152
+ });
153
+ expect(payload).toBe(true);
154
+ });
155
+ it('order by json field', () => {
156
+ const payload = _1.validatePayload({ order: ['status.title'] }, {
122
157
  rawAttributes: {
123
158
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
124
159
  },
125
160
  });
126
- }
127
- catch (error) {
128
- expect(error.statusCode).toBe(400);
129
- }
161
+ expect(payload).toBe(true);
162
+ });
163
+ it('order by json field desc', () => {
164
+ const payload = _1.validatePayload({ order: ['-status.title'] }, {
165
+ rawAttributes: {
166
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
167
+ },
168
+ });
169
+ expect(payload).toBe(true);
170
+ });
171
+ it('try order by json field that doesnt exist', () => {
172
+ try {
173
+ _1.validatePayload({ order: ['-stas.title'] }, {
174
+ rawAttributes: {
175
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
176
+ },
177
+ });
178
+ }
179
+ catch (error) {
180
+ expect(error.statusCode).toBe(400);
181
+ }
182
+ });
130
183
  });
131
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",