@autofleet/sheilta 1.2.2 → 1.2.3-beta1

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,16 +1,6 @@
1
1
  declare type OrderItem = string | [string, string];
2
2
  declare type SequelizeOrder = string | OrderItem[];
3
- declare const formatPayload: ({ order, page, perPage, include, query, }: {
4
- order: any;
5
- page?: number;
6
- perPage?: number;
7
- include?: any[];
8
- query?: {};
9
- }, model?: any) => {
10
- query: {};
11
- order: SequelizeOrder[];
12
- page: any;
13
- perPage: any;
14
- include: any;
15
- };
16
- export default formatPayload;
3
+ export declare const formatOrder: ({ order, }: {
4
+ order?: any[];
5
+ }) => SequelizeOrder[] | undefined;
6
+ export {};
@@ -1,43 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatOrder = void 0;
3
4
  const utils_1 = require("../utils");
4
5
  const DESCENDING_KEY = 'DESC';
5
- const formatOrder = ({ order = [], associationModels = [], }) => (order.length === 0 ? undefined :
6
+ exports.formatOrder = ({ order = [], }) => (order.length === 0 ? undefined :
6
7
  order.map((o) => {
7
- const formattedOrder = [utils_1.extractAttributeNameFromOrder(o, associationModels)];
8
8
  const isOrderDescOrder = utils_1.isOrderDesc(o);
9
- const isOrderAssociation = utils_1.isAttributeByAssociation(isOrderDescOrder
10
- ? o.split(utils_1.ORDER_PREFIX)[1]
11
- : o, associationModels);
12
- if (isOrderAssociation) {
13
- formattedOrder.push(utils_1.extractAssociatedAttributeNameFromOrder(o));
14
- }
9
+ let column = o;
15
10
  if (isOrderDescOrder) {
16
- formattedOrder.push(DESCENDING_KEY);
11
+ column = utils_1.extractAttributeNameFromOrder(o);
12
+ return [column, DESCENDING_KEY];
17
13
  }
18
- return formattedOrder;
14
+ return [column];
19
15
  }));
20
- const formatPage = page => page || utils_1.PAGE_DEFAULT;
21
- const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
22
- const formatInclude = (include, associationsMap = {}) => include.map(i => associationsMap[i.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) => {
26
- const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
27
- const formattedOrder = formatOrder({
28
- order,
29
- associationModels,
30
- });
31
- const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
32
- const formattedPage = formatPage(page);
33
- const formattedPerPage = formatPerPage(perPage);
34
- const formattedQuery = formatQuery(query, associationModels);
35
- return {
36
- query: formattedQuery,
37
- order: formattedOrder,
38
- page: formattedPage,
39
- perPage: formattedPerPage,
40
- include: formattedInclude,
41
- };
42
- };
43
- exports.default = formatPayload;
@@ -1,103 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const _1 = __importDefault(require("."));
3
+ const _1 = require(".");
7
4
  describe('formatting test', () => {
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 } }));
23
- });
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 } }));
5
+ it('check order formatting', () => {
6
+ const payload = _1.formatOrder({
7
+ order: ['startTime', '-endTime'],
41
8
  });
9
+ expect(JSON.stringify(payload)).toBe(JSON.stringify([['startTime'], ['endTime', 'DESC']]));
42
10
  });
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']]));
49
- });
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']]));
55
- });
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']]));
68
- });
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']]));
11
+ it('check order formatting', () => {
12
+ const payload = _1.formatOrder({
13
+ order: ['startTime', 'endTime'],
101
14
  });
15
+ expect(JSON.stringify(payload)).toBe(JSON.stringify([['startTime'], ['endTime']]));
102
16
  });
103
17
  });
@@ -1,4 +1,2 @@
1
- export declare const newQueryValidationMiddleware: (inner?: string) => (model: any) => (req: any, res: any, next: any) => Promise<any>;
2
- export declare const newQueryFormatMiddleware: (inner?: string) => (model: any) => (req: any, res: any, next: any) => Promise<any>;
3
1
  export declare const queryValidationMiddleware: (model: any) => (req: any, res: any, next: any) => Promise<any>;
4
- export declare const queryFormatMiddleware: (model: any) => (req: any, res: any, next: any) => Promise<any>;
2
+ export declare const queryFormatMiddleware: () => (req: any, res: any, next: any) => Promise<any>;
@@ -8,24 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.queryFormatMiddleware = exports.queryValidationMiddleware = exports.newQueryFormatMiddleware = exports.newQueryValidationMiddleware = void 0;
12
+ exports.queryFormatMiddleware = exports.queryValidationMiddleware = void 0;
16
13
  const errors_1 = require("@autofleet/errors");
17
- const formatter_1 = __importDefault(require("../formatter"));
14
+ const formatter_1 = require("../formatter");
18
15
  const validations_1 = require("../validations");
19
- exports.newQueryValidationMiddleware = (inner = 'body') => model => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
20
- const { query, attributes, order, page, perPage, include, } = req[inner];
16
+ exports.queryValidationMiddleware = model => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const { query, attributes, order, } = req.body;
21
18
  try {
22
19
  validations_1.validatePayload({
23
20
  query,
24
21
  attributes,
25
22
  order,
26
- page,
27
- perPage,
28
- include,
29
23
  }, model);
30
24
  return next();
31
25
  }
@@ -41,21 +35,11 @@ exports.newQueryValidationMiddleware = (inner = 'body') => model => (req, res, n
41
35
  });
42
36
  }
43
37
  });
44
- exports.newQueryFormatMiddleware = (inner = 'body') => model => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
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,
38
+ exports.queryFormatMiddleware = () => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const { order, } = req.body;
40
+ const formattedOrder = formatter_1.formatOrder({
48
41
  order,
49
- page,
50
- perPage,
51
- include,
52
- }, model);
53
- req[inner].query = formattedQuery;
54
- req[inner].order = formattedOrder;
55
- req[inner].page = formattedPage;
56
- req[inner].perPage = formattedPerPage;
57
- req[inner].include = formattedInclude;
42
+ });
43
+ req.body.order = formattedOrder;
58
44
  return next();
59
45
  });
60
- exports.queryValidationMiddleware = exports.newQueryValidationMiddleware();
61
- exports.queryFormatMiddleware = exports.newQueryFormatMiddleware();
@@ -17,8 +17,6 @@ exports.OPERATORS = [
17
17
  'between',
18
18
  'and',
19
19
  'or',
20
- 'overlap',
21
- 'contains',
22
20
  ];
23
21
  exports.OPERATOR_PREFIX = '$';
24
22
  exports.formatOperators = (Sequelize) => {
package/lib/utils.d.ts CHANGED
@@ -1,13 +1,3 @@
1
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;
2
+ export declare const extractAttributeNameFromOrder: (order: any) => string;
11
3
  export declare const isOrderDesc: (order: any) => boolean;
12
- export declare const throwBadRequestError: (message: string) => never;
13
- export declare const extractAssociatedAttributeNameFromOrder: (order: any) => string;
package/lib/utils.js CHANGED
@@ -1,31 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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
- const errors_1 = require("@autofleet/errors");
5
- const operators_1 = require("./operators");
3
+ exports.isOrderDesc = exports.extractAttributeNameFromOrder = exports.ORDER_PREFIX = void 0;
6
4
  exports.ORDER_PREFIX = '-';
7
- exports.ASSOCIATION_PREFIX = '.';
8
- exports.PER_PAGE_DEFAULT = 20;
9
- exports.PAGE_DEFAULT = 1;
10
- exports.PER_PAGE_MAX_LIMIT = 100;
11
- exports.PER_PAGE_MIN_LIMIT = 1;
12
- exports.PAGE_MIN = 1;
13
- exports.wrapAttributeWithOperator = attribute => `${operators_1.OPERATOR_PREFIX}${attribute}${operators_1.OPERATOR_PREFIX}`;
14
- exports.isAttributeByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
15
- && associatedModels.includes(attributeName.split(exports.ASSOCIATION_PREFIX)[0]);
16
- exports.extractAttributeNameFromOrder = (order, associationModels) => {
17
- let formattedOrder = order;
18
- if (order.includes(exports.ORDER_PREFIX)) {
19
- // eslint-disable-next-line prefer-destructuring
20
- formattedOrder = formattedOrder.split(exports.ORDER_PREFIX)[1];
21
- }
22
- if (exports.isAttributeByAssociation(formattedOrder, associationModels)) {
23
- [formattedOrder] = formattedOrder.split(exports.ASSOCIATION_PREFIX);
24
- }
25
- return formattedOrder;
26
- };
5
+ exports.extractAttributeNameFromOrder = (order) => order.split(exports.ORDER_PREFIX)[1];
27
6
  exports.isOrderDesc = (order) => order.includes(exports.ORDER_PREFIX);
28
- exports.throwBadRequestError = (message) => {
29
- throw new errors_1.BadRequest([{ message }], null);
30
- };
31
- exports.extractAssociatedAttributeNameFromOrder = (order) => order.split(exports.ASSOCIATION_PREFIX)[1];
@@ -1,8 +1,5 @@
1
- export declare const validatePayload: ({ query, order, attributes, include, page, perPage, }: {
1
+ export declare const validatePayload: ({ query, order, attributes, }: {
2
2
  query?: {};
3
3
  order?: any[];
4
4
  attributes?: any[];
5
- include?: any[];
6
- page?: number;
7
- perPage?: number;
8
- }, model?: any) => boolean;
5
+ }, model: any) => boolean;
@@ -4,87 +4,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.validatePayload = void 0;
7
+ const errors_1 = require("@autofleet/errors");
7
8
  const lodash_1 = __importDefault(require("lodash"));
8
9
  const utils_1 = require("../utils");
9
10
  const operators_1 = require("../operators");
10
11
  const validateOperator = (operator) => operators_1.OPERATORS.includes(operator.split(operators_1.OPERATOR_PREFIX)[1]);
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);
14
- const validateSingleOrder = (currentOrder, rawAttributes, associationModels) => {
12
+ const validateQueryAttribute = (attribute, modelAttributes) => modelAttributes.includes(attribute);
13
+ const validateSingleOrder = (currentOrder, rawAttributes) => {
15
14
  const isOrderDescOrder = utils_1.isOrderDesc(currentOrder);
16
15
  if (isOrderDescOrder && currentOrder[0] !== utils_1.ORDER_PREFIX) {
17
- utils_1.throwBadRequestError(`${utils_1.ORDER_PREFIX} must be only at the beginning of the word`);
16
+ throw new errors_1.BadRequest(`${utils_1.ORDER_PREFIX} must be only at the beginning of the word`, null);
18
17
  }
19
- const orderStringWithoutDesc = isOrderDescOrder ?
20
- currentOrder.split(utils_1.ORDER_PREFIX)[1] : currentOrder;
21
- const isOrderAssociation = utils_1.isAttributeByAssociation(orderStringWithoutDesc, associationModels);
22
- let formattedOrderString = utils_1.extractAttributeNameFromOrder(currentOrder, associationModels);
23
- if (!isOrderAssociation && formattedOrderString.includes(utils_1.ASSOCIATION_PREFIX)) {
24
- [formattedOrderString] = formattedOrderString.split(utils_1.ASSOCIATION_PREFIX);
25
- }
26
- if (!(rawAttributes.includes(formattedOrderString) || isOrderAssociation)) {
27
- utils_1.throwBadRequestError(`${currentOrder} is invalid`);
18
+ const formattedOrderString = isOrderDescOrder ?
19
+ utils_1.extractAttributeNameFromOrder(currentOrder) :
20
+ currentOrder;
21
+ if (!rawAttributes.includes(formattedOrderString)) {
22
+ throw new errors_1.BadRequest(`${currentOrder} is invalid`, null);
28
23
  }
29
24
  };
30
25
  const validateSingleAttribute = (currentAttribute, rawAttributes) => {
31
26
  if (!rawAttributes.includes(currentAttribute)) {
32
- utils_1.throwBadRequestError(`${currentAttribute} is invalid`);
27
+ throw new errors_1.BadRequest(`${currentAttribute} is invalid`, null);
33
28
  }
34
29
  };
35
- const validateOrderAttributes = (order, rawAttributes, associationModels = []) => {
36
- order.map(o => validateSingleOrder(o, rawAttributes, associationModels));
30
+ const validateOrderAttributes = (order, rawAttributes) => {
31
+ order.map(o => validateSingleOrder(o, rawAttributes));
37
32
  };
38
33
  const validateAttributes = (attributes, rawAttributes) => {
39
34
  attributes.map(a => validateSingleAttribute(a, rawAttributes));
40
35
  };
41
- const validateQueryPayload = (query, rawAttributes, associationModels = []) => {
36
+ const validateQueryPayload = (query, rawAttributes) => {
42
37
  // eslint-disable-next-line array-callback-return
43
38
  Object.keys(query).map((key) => {
44
39
  const value = query[key];
45
40
  if (lodash_1.default.isArray(value)) {
46
41
  if (lodash_1.default.isObject(value[0])) {
47
- value.map(v => validateQueryPayload(v, rawAttributes, associationModels));
42
+ value.map(v => validateQueryPayload(v, rawAttributes));
48
43
  }
49
44
  }
50
- else if (validateOperator(key)
51
- || validateQueryAttribute(key, rawAttributes, associationModels)) {
45
+ else if (validateOperator(key) || validateQueryAttribute(key, rawAttributes)) {
52
46
  if (lodash_1.default.isObject(value)) {
53
47
  validateQueryPayload(value, rawAttributes);
54
48
  }
55
49
  }
56
50
  else {
57
- utils_1.throwBadRequestError(`invalid key: ${key}`);
51
+ throw new errors_1.BadRequest(`invalid key: ${key}`, null);
58
52
  }
59
53
  });
60
54
  };
61
- const validatePagination = ({ page, perPage, }) => {
62
- if (page < utils_1.PAGE_MIN) {
63
- utils_1.throwBadRequestError('Page must be greater than 0');
64
- }
65
- if (perPage > utils_1.PER_PAGE_MAX_LIMIT || perPage < utils_1.PER_PAGE_MIN_LIMIT) {
66
- utils_1.throwBadRequestError(`PerPage must be between ${utils_1.PER_PAGE_MIN_LIMIT} to ${utils_1.PER_PAGE_MAX_LIMIT}`);
67
- }
68
- };
69
- const validateIncludePayload = (include, associations) => {
70
- const associationsKeys = Object.keys(associations);
71
- include.forEach((i) => {
72
- validateQueryAttribute(i.model, associationsKeys);
73
- const { rawAttributes } = associations[i.model].target;
74
- if (include.where) {
75
- validateQueryPayload(i.where, rawAttributes);
76
- }
77
- if (include.order) {
78
- validateOrderAttributes(i.order, rawAttributes);
79
- }
80
- if (!lodash_1.default.isNil(include.required) && !lodash_1.default.isBoolean(include.required)) {
81
- utils_1.throwBadRequestError('include.required must be a boolean');
82
- }
83
- });
84
- };
85
- exports.validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, }, model) => {
55
+ exports.validatePayload = ({ query = {}, order = [], attributes = [], }, model) => {
86
56
  const rawAttributes = Object.keys(model.rawAttributes);
87
- const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
88
57
  if (!attributes || attributes.length === 0) {
89
58
  // eslint-disable-next-line no-param-reassign
90
59
  attributes = rawAttributes;
@@ -92,14 +61,7 @@ exports.validatePayload = ({ query = {}, order = [], attributes = [], include =
92
61
  else {
93
62
  validateAttributes(attributes, rawAttributes);
94
63
  }
95
- validateOrderAttributes(order, rawAttributes, associationModels);
96
- validateQueryPayload(query, rawAttributes, associationModels);
97
- if (include.length) {
98
- validateIncludePayload(include, model === null || model === void 0 ? void 0 : model.associations);
99
- }
100
- validatePagination({
101
- page,
102
- perPage,
103
- });
64
+ validateOrderAttributes(order, rawAttributes);
65
+ validateQueryPayload(query, rawAttributes);
104
66
  return true;
105
67
  };
@@ -38,147 +38,44 @@ const query = {
38
38
  };
39
39
  const order = ['startTime', '-endTime'];
40
40
  describe('validations test', () => {
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);
49
- });
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);
63
- });
64
- it('check query by included model field', () => {
65
- const payload = _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
- _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
- }
41
+ it('check query validation', () => {
42
+ const payload = _1.validatePayload({ query }, {
43
+ rawAttributes: {
44
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
45
+ },
98
46
  });
47
+ expect(payload).toBe(true);
99
48
  });
100
- describe('order validation', () => {
101
- it('check order validation', () => {
102
- const payload = _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
- _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
- _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
- }
49
+ it('check order validation', () => {
50
+ const payload = _1.validatePayload({ order }, {
51
+ rawAttributes: {
52
+ startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
53
+ },
132
54
  });
133
- it('order by included model', () => {
134
- const payload = _1.validatePayload({ order: ['status.title'] }, {
55
+ expect(payload).toBe(true);
56
+ });
57
+ it('check order validation - order does not exist', () => {
58
+ try {
59
+ _1.validatePayload({ order: ['aviv'] }, {
135
60
  rawAttributes: {
136
61
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
137
62
  },
138
- associations: {
139
- status: {},
140
- },
141
63
  });
142
- expect(payload).toBe(true);
143
- });
144
- it('order by included model descending', () => {
145
- const payload = _1.validatePayload({ order: ['-status.title'] }, {
64
+ }
65
+ catch (error) {
66
+ expect(error.statusCode).toBe(400);
67
+ }
68
+ });
69
+ it('check order validation - prefix in the wrong place', () => {
70
+ try {
71
+ _1.validatePayload({ order: ['startTime-', 'currencySymbol'] }, {
146
72
  rawAttributes: {
147
73
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
148
74
  },
149
- associations: {
150
- status: {},
151
- },
152
75
  });
153
- expect(payload).toBe(true);
154
- });
155
- it('order by json field', () => {
156
- const payload = _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 = _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
- });
76
+ }
77
+ catch (error) {
78
+ expect(error.statusCode).toBe(400);
79
+ }
183
80
  });
184
81
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-beta1",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",