@autofleet/sheilta 1.4.8-beta-5 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +110 -0
- package/lib/index.d.ts +110 -3
- package/lib/index.js +2 -8
- package/lib/index.js.map +1 -0
- package/package.json +35 -20
- package/lib/formatter/index.d.ts +0 -55
- package/lib/formatter/index.js +0 -245
- package/lib/formatter/index.test.d.ts +0 -1
- package/lib/formatter/index.test.js +0 -267
- package/lib/middleware/index.d.ts +0 -17
- package/lib/middleware/index.js +0 -92
- package/lib/operators/index.d.ts +0 -20
- package/lib/operators/index.js +0 -50
- package/lib/utils.d.ts +0 -14
- package/lib/utils.js +0 -43
- package/lib/validations/index.d.ts +0 -11
- package/lib/validations/index.js +0 -123
- package/lib/validations/index.test.d.ts +0 -1
- package/lib/validations/index.test.js +0 -219
package/lib/operators/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const OPERATORS: string[];
|
|
2
|
-
export declare const OPERATOR_PREFIX = "$";
|
|
3
|
-
export declare const OPERATORS_TO_SQL: {
|
|
4
|
-
$eq: string;
|
|
5
|
-
$ne: string;
|
|
6
|
-
$gte: string;
|
|
7
|
-
$gt: string;
|
|
8
|
-
$lte: string;
|
|
9
|
-
$lt: string;
|
|
10
|
-
$not: string;
|
|
11
|
-
$in: string;
|
|
12
|
-
$notIn: string;
|
|
13
|
-
$is: string;
|
|
14
|
-
$like: string;
|
|
15
|
-
$iLike: string;
|
|
16
|
-
$notLike: string;
|
|
17
|
-
$and: string;
|
|
18
|
-
$or: string;
|
|
19
|
-
};
|
|
20
|
-
export declare const formatOperators: (Sequelize: any) => {};
|
package/lib/operators/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatOperators = exports.OPERATORS_TO_SQL = exports.OPERATOR_PREFIX = exports.OPERATORS = void 0;
|
|
4
|
-
exports.OPERATORS = [
|
|
5
|
-
'eq',
|
|
6
|
-
'ne',
|
|
7
|
-
'gte',
|
|
8
|
-
'gt',
|
|
9
|
-
'lte',
|
|
10
|
-
'lt',
|
|
11
|
-
'not',
|
|
12
|
-
'in',
|
|
13
|
-
'notIn',
|
|
14
|
-
'is',
|
|
15
|
-
'like',
|
|
16
|
-
'iLike',
|
|
17
|
-
'notLike',
|
|
18
|
-
'between',
|
|
19
|
-
'and',
|
|
20
|
-
'or',
|
|
21
|
-
'overlap',
|
|
22
|
-
'contains',
|
|
23
|
-
];
|
|
24
|
-
exports.OPERATOR_PREFIX = '$';
|
|
25
|
-
exports.OPERATORS_TO_SQL = {
|
|
26
|
-
$eq: '=',
|
|
27
|
-
$ne: '!=',
|
|
28
|
-
$gte: '>=',
|
|
29
|
-
$gt: '>',
|
|
30
|
-
$lte: '<=',
|
|
31
|
-
$lt: '<',
|
|
32
|
-
$not: 'NOT',
|
|
33
|
-
$in: 'IN',
|
|
34
|
-
$notIn: 'NOT IN',
|
|
35
|
-
$is: 'IS',
|
|
36
|
-
$like: 'LIKE',
|
|
37
|
-
$iLike: 'ILIKE',
|
|
38
|
-
$notLike: 'NOT LIKE',
|
|
39
|
-
$and: 'AND',
|
|
40
|
-
$or: 'OR',
|
|
41
|
-
};
|
|
42
|
-
const formatOperators = (Sequelize) => {
|
|
43
|
-
const { Op } = Sequelize;
|
|
44
|
-
return exports.OPERATORS.reduce((map, o) => {
|
|
45
|
-
// eslint-disable-next-line no-param-reassign
|
|
46
|
-
map[`${exports.OPERATOR_PREFIX + o}`] = Op[o];
|
|
47
|
-
return map;
|
|
48
|
-
}, {});
|
|
49
|
-
};
|
|
50
|
-
exports.formatOperators = formatOperators;
|
package/lib/utils.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const ORDER_PREFIX = "-";
|
|
2
|
-
export declare const ASSOCIATION_PREFIX = ".";
|
|
3
|
-
export declare const PER_PAGE_DEFAULT = 20;
|
|
4
|
-
export declare const PAGE_DEFAULT = 1;
|
|
5
|
-
export declare const PER_PAGE_MAX_LIMIT = 100;
|
|
6
|
-
export declare const PER_PAGE_MIN_LIMIT = 1;
|
|
7
|
-
export declare const PAGE_MIN = 1;
|
|
8
|
-
export declare const wrapAttributeWithOperator: (attribute: any) => string;
|
|
9
|
-
export declare const isAttributeByAssociation: (attributeName: any, associatedModels: any) => boolean;
|
|
10
|
-
export declare const extractAttributeNameFromOrder: (order: any, associationModels: any) => string;
|
|
11
|
-
export declare const isOrderDesc: (order: any) => boolean;
|
|
12
|
-
export declare const throwBadRequestError: (message: string) => never;
|
|
13
|
-
export declare const extractAssociatedAttributeNameFromOrder: (order: any) => string;
|
|
14
|
-
export declare const generateRandomString: (length?: number) => string;
|
package/lib/utils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRandomString = 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
|
-
const errors_1 = require("@autofleet/errors");
|
|
5
|
-
const operators_1 = require("./operators");
|
|
6
|
-
const randomInt = max => Math.floor(Math.random() * Math.floor(max));
|
|
7
|
-
exports.ORDER_PREFIX = '-';
|
|
8
|
-
exports.ASSOCIATION_PREFIX = '.';
|
|
9
|
-
exports.PER_PAGE_DEFAULT = 20;
|
|
10
|
-
exports.PAGE_DEFAULT = 1;
|
|
11
|
-
exports.PER_PAGE_MAX_LIMIT = 100;
|
|
12
|
-
exports.PER_PAGE_MIN_LIMIT = 1;
|
|
13
|
-
exports.PAGE_MIN = 1;
|
|
14
|
-
const wrapAttributeWithOperator = attribute => `${operators_1.OPERATOR_PREFIX}${attribute}${operators_1.OPERATOR_PREFIX}`;
|
|
15
|
-
exports.wrapAttributeWithOperator = wrapAttributeWithOperator;
|
|
16
|
-
const isAttributeByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
|
|
17
|
-
&& associatedModels.includes(attributeName.split(exports.ASSOCIATION_PREFIX)[0]);
|
|
18
|
-
exports.isAttributeByAssociation = isAttributeByAssociation;
|
|
19
|
-
const extractAttributeNameFromOrder = (order, associationModels) => {
|
|
20
|
-
let formattedOrder = order;
|
|
21
|
-
if (order.includes(exports.ORDER_PREFIX)) {
|
|
22
|
-
// eslint-disable-next-line prefer-destructuring
|
|
23
|
-
formattedOrder = formattedOrder.split(exports.ORDER_PREFIX)[1];
|
|
24
|
-
}
|
|
25
|
-
if ((0, exports.isAttributeByAssociation)(formattedOrder, associationModels)) {
|
|
26
|
-
[formattedOrder] = formattedOrder.split(exports.ASSOCIATION_PREFIX);
|
|
27
|
-
}
|
|
28
|
-
return formattedOrder;
|
|
29
|
-
};
|
|
30
|
-
exports.extractAttributeNameFromOrder = extractAttributeNameFromOrder;
|
|
31
|
-
const isOrderDesc = (order) => order.includes(exports.ORDER_PREFIX);
|
|
32
|
-
exports.isOrderDesc = isOrderDesc;
|
|
33
|
-
const throwBadRequestError = (message) => {
|
|
34
|
-
throw new errors_1.BadRequest([new Error(message)], null);
|
|
35
|
-
};
|
|
36
|
-
exports.throwBadRequestError = throwBadRequestError;
|
|
37
|
-
const extractAssociatedAttributeNameFromOrder = (order) => order.split(exports.ASSOCIATION_PREFIX)[1];
|
|
38
|
-
exports.extractAssociatedAttributeNameFromOrder = extractAssociatedAttributeNameFromOrder;
|
|
39
|
-
const generateRandomString = (length = 5) => {
|
|
40
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
41
|
-
return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');
|
|
42
|
-
};
|
|
43
|
-
exports.generateRandomString = generateRandomString;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { MiddlewareValidationOption } from '../middleware';
|
|
2
|
-
export declare const validatePayload: ({ query, order, attributes, include, page, perPage, enrichments, group, }: {
|
|
3
|
-
query?: {};
|
|
4
|
-
order?: any[];
|
|
5
|
-
attributes?: any[];
|
|
6
|
-
include?: any[];
|
|
7
|
-
page?: number;
|
|
8
|
-
perPage?: number;
|
|
9
|
-
enrichments?: any[];
|
|
10
|
-
group?: any[];
|
|
11
|
-
}, model?: any, options?: MiddlewareValidationOption) => boolean;
|
package/lib/validations/index.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validatePayload = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const operators_1 = require("../operators");
|
|
6
|
-
const validateOperator = (operator) => operators_1.OPERATORS.includes(operator.split(operators_1.OPERATOR_PREFIX)[1]);
|
|
7
|
-
const validateQueryAttribute = (attribute, modelAttributes = [], associationModels = [], additionalAllowedAttributes = []) => ([...modelAttributes, ...associationModels].includes(attribute.includes(utils_1.ASSOCIATION_PREFIX) ? attribute.split(utils_1.ASSOCIATION_PREFIX)[0] : attribute)
|
|
8
|
-
|| additionalAllowedAttributes.includes(attribute));
|
|
9
|
-
const validateSingleOrder = (currentOrder, rawAttributes, associationModels, options = {}) => {
|
|
10
|
-
const isOrderDescOrder = (0, utils_1.isOrderDesc)(currentOrder);
|
|
11
|
-
if (isOrderDescOrder && currentOrder[0] !== utils_1.ORDER_PREFIX) {
|
|
12
|
-
(0, utils_1.throwBadRequestError)(`${utils_1.ORDER_PREFIX} must be only at the beginning of the word`);
|
|
13
|
-
}
|
|
14
|
-
const orderStringWithoutDesc = isOrderDescOrder ? currentOrder.split(utils_1.ORDER_PREFIX)[1] : currentOrder;
|
|
15
|
-
const isOrderAssociation = (0, utils_1.isAttributeByAssociation)(orderStringWithoutDesc, associationModels);
|
|
16
|
-
let formattedOrderString = (0, utils_1.extractAttributeNameFromOrder)(currentOrder, associationModels);
|
|
17
|
-
const isLiteralAttribute = options?.literalAttributes?.map((la) => la.attribute)?.includes(orderStringWithoutDesc);
|
|
18
|
-
if (!isOrderAssociation && formattedOrderString.includes(utils_1.ASSOCIATION_PREFIX)) {
|
|
19
|
-
[formattedOrderString] = formattedOrderString.split(utils_1.ASSOCIATION_PREFIX);
|
|
20
|
-
}
|
|
21
|
-
if (!(rawAttributes.includes(formattedOrderString) || isOrderAssociation || isLiteralAttribute)) {
|
|
22
|
-
(0, utils_1.throwBadRequestError)(`${currentOrder} is invalid. isLiteralAttribute: ${isLiteralAttribute}`);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const validateSingleAttribute = (currentAttribute, rawAttributes) => {
|
|
26
|
-
if (!rawAttributes.includes(currentAttribute)) {
|
|
27
|
-
(0, utils_1.throwBadRequestError)(`${currentAttribute} is invalid`);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const validateOrderAttributes = (order, rawAttributes, associationModels = [], options = {}) => {
|
|
31
|
-
order.forEach((o) => validateSingleOrder(o, rawAttributes, associationModels, options));
|
|
32
|
-
};
|
|
33
|
-
const validateAttributes = (attributes, rawAttributes) => {
|
|
34
|
-
attributes.forEach((a) => validateSingleAttribute(a, rawAttributes));
|
|
35
|
-
};
|
|
36
|
-
const validateEnrichments = (enrichments, options) => {
|
|
37
|
-
const enrichmentKeys = Array.isArray(enrichments) ? enrichments : Object.keys(enrichments);
|
|
38
|
-
if (!enrichmentKeys?.length) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const invalidEnrichment = enrichmentKeys.find((enrichment) => !options?.enrichmentAttributes?.includes(enrichment));
|
|
42
|
-
if (invalidEnrichment) {
|
|
43
|
-
(0, utils_1.throwBadRequestError)(`enrichment attribute ${invalidEnrichment} is invalid`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const validateQueryPayload = (query, rawAttributes, associationModels = [], additionalAllowedAttributes = []) => {
|
|
47
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
48
|
-
if (Array.isArray(value)) {
|
|
49
|
-
if (value[0] && typeof value[0] === 'object') {
|
|
50
|
-
value.map((v) => validateQueryPayload(v, rawAttributes, associationModels, additionalAllowedAttributes));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (validateOperator(key) || validateQueryAttribute(key, rawAttributes, associationModels, additionalAllowedAttributes)) {
|
|
54
|
-
if (value && typeof value === 'object') {
|
|
55
|
-
validateQueryPayload(value, rawAttributes, [], additionalAllowedAttributes);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
(0, utils_1.throwBadRequestError)(`invalid key: ${key}`);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
const validatePagination = ({ page, perPage, }) => {
|
|
64
|
-
if (page < utils_1.PAGE_MIN) {
|
|
65
|
-
(0, utils_1.throwBadRequestError)('Page must be greater than 0');
|
|
66
|
-
}
|
|
67
|
-
if (perPage > utils_1.PER_PAGE_MAX_LIMIT || perPage < utils_1.PER_PAGE_MIN_LIMIT) {
|
|
68
|
-
(0, utils_1.throwBadRequestError)(`PerPage must be between ${utils_1.PER_PAGE_MIN_LIMIT} to ${utils_1.PER_PAGE_MAX_LIMIT}`);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const validateIncludePayload = (include, associations) => {
|
|
72
|
-
const associationsKeys = Object.keys(associations);
|
|
73
|
-
include.forEach((i) => {
|
|
74
|
-
validateQueryAttribute(i.model, associationsKeys);
|
|
75
|
-
const target = associations[i.model]?.target;
|
|
76
|
-
if (!target) {
|
|
77
|
-
(0, utils_1.throwBadRequestError)('model not found in associations');
|
|
78
|
-
}
|
|
79
|
-
const { rawAttributes } = target;
|
|
80
|
-
const attributeKeys = Object.keys(rawAttributes);
|
|
81
|
-
if (i.where) {
|
|
82
|
-
validateQueryPayload(i.where, attributeKeys);
|
|
83
|
-
}
|
|
84
|
-
if (i.order) {
|
|
85
|
-
validateOrderAttributes(i.order, attributeKeys);
|
|
86
|
-
}
|
|
87
|
-
if (i.attributes) {
|
|
88
|
-
validateAttributes(i.attributes, attributeKeys);
|
|
89
|
-
}
|
|
90
|
-
if (![null, undefined, true, false].includes(i.required)) {
|
|
91
|
-
(0, utils_1.throwBadRequestError)('include.required must be a boolean');
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
const validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, enrichments = [], group = [], }, model, options = {}) => {
|
|
96
|
-
const rawAttributes = Object.keys(model.rawAttributes);
|
|
97
|
-
const associationModels = Object.keys(model?.associations || {});
|
|
98
|
-
if (!attributes || attributes.length === 0) {
|
|
99
|
-
// eslint-disable-next-line no-param-reassign
|
|
100
|
-
attributes = rawAttributes;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
validateAttributes(attributes, rawAttributes);
|
|
104
|
-
}
|
|
105
|
-
validateOrderAttributes(order, rawAttributes, associationModels, options);
|
|
106
|
-
validateQueryPayload(query, rawAttributes, associationModels, options.additionalAllowedAttributes);
|
|
107
|
-
validateEnrichments(enrichments, options);
|
|
108
|
-
if (!Array.isArray(group)) {
|
|
109
|
-
(0, utils_1.throwBadRequestError)('group must be an array');
|
|
110
|
-
}
|
|
111
|
-
if (include.length && typeof include === 'object') {
|
|
112
|
-
validateIncludePayload(include, model?.associations);
|
|
113
|
-
}
|
|
114
|
-
else if (include && typeof include !== 'object') {
|
|
115
|
-
(0, utils_1.throwBadRequestError)('include must be an array');
|
|
116
|
-
}
|
|
117
|
-
validatePagination({
|
|
118
|
-
page,
|
|
119
|
-
perPage,
|
|
120
|
-
});
|
|
121
|
-
return true;
|
|
122
|
-
};
|
|
123
|
-
exports.validatePayload = validatePayload;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const _1 = require(".");
|
|
4
|
-
const query = {
|
|
5
|
-
$and: [
|
|
6
|
-
{
|
|
7
|
-
startTime: {
|
|
8
|
-
$gte: '2019-09-10 12:00:00',
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
endTime: {
|
|
13
|
-
$lt: '2019-09-07 12:00:00',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
$or: [
|
|
18
|
-
{
|
|
19
|
-
$and: [
|
|
20
|
-
{
|
|
21
|
-
currencySymbol: {
|
|
22
|
-
$eq: ['€', 'f'],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
currencyCode: {
|
|
27
|
-
$eq: 'EUR',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
startStationId: {
|
|
34
|
-
$eq: '1',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
const order = ['startTime', '-endTime'];
|
|
40
|
-
describe('validations test', () => {
|
|
41
|
-
describe('query validation', () => {
|
|
42
|
-
it('check query validation', () => {
|
|
43
|
-
const payload = (0, _1.validatePayload)({ query }, {
|
|
44
|
-
rawAttributes: {
|
|
45
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
expect(payload).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
it('check query by json property field', () => {
|
|
51
|
-
const payload = (0, _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);
|
|
63
|
-
});
|
|
64
|
-
it('check query by included model field', () => {
|
|
65
|
-
const payload = (0, _1.validatePayload)({
|
|
66
|
-
query: {
|
|
67
|
-
'status.name': {
|
|
68
|
-
$eq: 'a',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}, {
|
|
72
|
-
rawAttributes: {
|
|
73
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
74
|
-
},
|
|
75
|
-
associations: {
|
|
76
|
-
status: {},
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
expect(payload).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
it('check query by non existent field', () => {
|
|
82
|
-
try {
|
|
83
|
-
(0, _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
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('order validation', () => {
|
|
101
|
-
it('check order validation', () => {
|
|
102
|
-
const payload = (0, _1.validatePayload)({ order }, {
|
|
103
|
-
rawAttributes: {
|
|
104
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
expect(payload).toBe(true);
|
|
108
|
-
});
|
|
109
|
-
it('order does not exist', () => {
|
|
110
|
-
try {
|
|
111
|
-
(0, _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
|
-
}
|
|
120
|
-
});
|
|
121
|
-
it('prefix in the wrong place', () => {
|
|
122
|
-
try {
|
|
123
|
-
(0, _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
|
-
}
|
|
132
|
-
});
|
|
133
|
-
it('order by included model', () => {
|
|
134
|
-
const payload = (0, _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);
|
|
143
|
-
});
|
|
144
|
-
it('order by included model descending', () => {
|
|
145
|
-
const payload = (0, _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 = (0, _1.validatePayload)({ order: ['status.title'] }, {
|
|
157
|
-
rawAttributes: {
|
|
158
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
expect(payload).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
it('order by json field desc', () => {
|
|
164
|
-
const payload = (0, _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
|
-
(0, _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
|
-
});
|
|
183
|
-
it('try order by literal field that exist', () => {
|
|
184
|
-
const literalAttribute = { attribute: 'genericField', literal: 'void' };
|
|
185
|
-
const payload = (0, _1.validatePayload)({ order: [literalAttribute.attribute] }, {
|
|
186
|
-
rawAttributes: {
|
|
187
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
188
|
-
},
|
|
189
|
-
}, {
|
|
190
|
-
literalAttributes: [literalAttribute],
|
|
191
|
-
});
|
|
192
|
-
expect(payload).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
it('try order by literal field that exist - desc', () => {
|
|
195
|
-
const literalAttribute = { attribute: 'genericField', literal: 'void' };
|
|
196
|
-
const payload = (0, _1.validatePayload)({ order: [`-${literalAttribute.attribute}`] }, {
|
|
197
|
-
rawAttributes: {
|
|
198
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
199
|
-
},
|
|
200
|
-
}, {
|
|
201
|
-
literalAttributes: [literalAttribute],
|
|
202
|
-
});
|
|
203
|
-
expect(payload).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
it('try order by literal field that doesnt exist', () => {
|
|
206
|
-
const literalAttribute = { attribute: 'genericField', literal: 'void' };
|
|
207
|
-
try {
|
|
208
|
-
(0, _1.validatePayload)({ order: ['here'] }, {
|
|
209
|
-
rawAttributes: {
|
|
210
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
211
|
-
},
|
|
212
|
-
}, { literalAttributes: [literalAttribute] });
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
expect(error.statusCode).toBe(400);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|