@autofleet/sheilta 1.2.3-beta6 → 1.2.3

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,13 +1,11 @@
1
1
  declare type OrderItem = string | [string, string];
2
2
  declare type SequelizeOrder = string | OrderItem[];
3
- declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
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
8
  query?: {};
9
- attributes?: any;
10
- searchTerm?: any;
11
9
  }, model?: any) => {
12
10
  query: {};
13
11
  order: SequelizeOrder[];
@@ -30,14 +30,7 @@ const formatInclude = (include, associationsMap = {}) => {
30
30
  };
31
31
  const formatQuery = (query, associationModels) => Object.keys(query).reduce((acc, queryItemKey) => (Object.assign(Object.assign({}, acc), { [utils_1.isAttributeByAssociation(queryItemKey, associationModels)
32
32
  ? utils_1.wrapAttributeWithOperator(queryItemKey) : queryItemKey]: query[queryItemKey] })), {});
33
- const formatSearchTerm = (searchTerm, attributesToSend, rawAttributes) => ({
34
- $or: attributesToSend.filter(attrKey => rawAttributes[attrKey].type.key === 'STRING').map(attr => ({
35
- [attr]: {
36
- $iLike: `%${searchTerm}%`,
37
- },
38
- })),
39
- });
40
- const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = null, searchTerm = null, }, model) => {
33
+ const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, }, model) => {
41
34
  const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
42
35
  const formattedOrder = formatOrder({
43
36
  order,
@@ -46,17 +39,7 @@ const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.P
46
39
  const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
47
40
  const formattedPage = formatPage(page);
48
41
  const formattedPerPage = formatPerPage(perPage);
49
- let formattedQuery = formatQuery(query, associationModels);
50
- if (searchTerm) {
51
- const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
52
- const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
53
- formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
54
- $and: [
55
- formattedQuery,
56
- queryWithSearchTerm,
57
- ],
58
- };
59
- }
42
+ const formattedQuery = formatQuery(query, associationModels);
60
43
  return {
61
44
  query: formattedQuery,
62
45
  order: formattedOrder,
@@ -39,38 +39,6 @@ describe('formatting test', () => {
39
39
  });
40
40
  expect(JSON.stringify(query)).toBe(JSON.stringify({ '$status.field$': { $gt: 4 } }));
41
41
  });
42
- it('query with searchTerm', () => {
43
- const searchTerm = 'aviv';
44
- const { query } = _1.default({
45
- order: [],
46
- query: {
47
- 'json.field': {
48
- $gt: 4,
49
- },
50
- },
51
- searchTerm,
52
- }, {
53
- rawAttributes: {
54
- startTime: '', endTime: '',
55
- },
56
- });
57
- expect(JSON.stringify(query)).toBe(JSON.stringify({
58
- $and: [{ 'json.field': { $gt: 4 } }, {
59
- $or: [
60
- {
61
- startTime: {
62
- $iLike: searchTerm,
63
- },
64
- },
65
- {
66
- endTime: {
67
- $iLike: searchTerm,
68
- },
69
- },
70
- ],
71
- }],
72
- }));
73
- });
74
42
  });
75
43
  describe('order formatting', () => {
76
44
  it('simple check', () => {
@@ -42,15 +42,13 @@ 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, query, attributes, searchTerm, } = req[inner];
45
+ const { order, page, perPage, include, query, } = req[inner];
46
46
  const { query: formattedQuery, order: formattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, } = formatter_1.default({
47
47
  query,
48
48
  order,
49
49
  page,
50
50
  perPage,
51
51
  include,
52
- attributes,
53
- searchTerm,
54
52
  }, model);
55
53
  req[inner].query = formattedQuery;
56
54
  req[inner].order = formattedOrder;
@@ -13,7 +13,6 @@ exports.OPERATORS = [
13
13
  'notIn',
14
14
  'is',
15
15
  'like',
16
- 'iLike',
17
16
  'notLike',
18
17
  'between',
19
18
  'and',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.2.3-beta6",
3
+ "version": "1.2.3",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",