@autofleet/sheilta 1.3.5-beta.2 → 1.3.5

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.
@@ -5,7 +5,6 @@ export declare type FormatPayloadOptions = {
5
5
  includeRawPayload?: boolean;
6
6
  literalAttributes?: LiteralAttribute[];
7
7
  DBFormatter?: any;
8
- skipSearchTermFormat?: boolean;
9
8
  };
10
9
  declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
11
10
  order?: any[];
@@ -16,9 +15,7 @@ declare const formatPayload: ({ order, page, perPage, include, query, attributes
16
15
  attributes?: any;
17
16
  searchTerm?: any;
18
17
  }, model?: any, options?: any) => {
19
- attributes: {
20
- include: any[];
21
- };
18
+ attributes: any[];
22
19
  query: {};
23
20
  order: SequelizeOrder[];
24
21
  page: any;
@@ -65,9 +65,9 @@ const formatQuery = (query, associationModels) => {
65
65
  formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] = queryItemValue;
66
66
  return;
67
67
  }
68
- const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
69
- ? utils_1.wrapAttributeWithOperator(queryItemKey)
70
- : queryItemKey;
68
+ const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels) ?
69
+ utils_1.wrapAttributeWithOperator(queryItemKey) :
70
+ queryItemKey;
71
71
  formattedQuery[key] = queryItemValue;
72
72
  });
73
73
  const formattedScopes = Array.from(formattedScopeMap.entries()).map(([scopeName, scopeValue]) => {
@@ -98,13 +98,12 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
98
98
  });
99
99
  const [filteredFormattedOrder, filteredLiteralAttributes] = getAttributeFromOrder(formattedOrder, options);
100
100
  const allAttributes = [...filteredLiteralAttributes, ...(attributes || [])];
101
- const formattedAttribute = allAttributes.length ? { include: allAttributes } : null;
102
101
  const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
103
102
  const formattedPage = formatPage(page);
104
103
  const formattedPerPage = formatPerPage(perPage);
105
104
  const result = formatQuery(query, associationModels);
106
105
  let { formattedQuery } = result;
107
- if (searchTerm && !(options === null || options === void 0 ? void 0 : options.skipSearchTermFormat)) {
106
+ if (searchTerm) {
108
107
  const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
109
108
  const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
110
109
  formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
@@ -114,6 +113,6 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
114
113
  ],
115
114
  };
116
115
  }
117
- return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, (formattedAttribute && { attributes: formattedAttribute }));
116
+ return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, ((allAttributes.length > 0) && { attributes: allAttributes }));
118
117
  };
119
118
  exports.default = formatPayload;
@@ -202,12 +202,13 @@ describe('formatting test', () => {
202
202
  });
203
203
  expect(JSON.stringify(order)).toBe(JSON.stringify([[`${literalAttribute.attribute} ASC`], ['id']]));
204
204
  expect(JSON.stringify(attributes))
205
- .toBe(JSON.stringify({ include: [literalAttribute.literal] }));
205
+ .toBe(JSON.stringify([literalAttribute.literal]));
206
206
  });
207
207
  it('by literal field descending', () => {
208
208
  const literalAttribute = { attribute: 'genericField', literal: ['void', 'field'] };
209
209
  const { order, attributes } = _1.default({
210
210
  order: [`-${literalAttribute.attribute}`, 'currencySymbol'],
211
+ attributes: ['endTime'],
211
212
  }, {
212
213
  rawAttributes: {
213
214
  startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
@@ -217,9 +218,7 @@ describe('formatting test', () => {
217
218
  });
218
219
  expect(JSON.stringify(order)).toBe(JSON.stringify([[`${literalAttribute.attribute} DESC`], ['currencySymbol'], ['id']]));
219
220
  expect(JSON.stringify(attributes))
220
- .toBe(JSON.stringify({
221
- include: [[literalAttribute.literal[0], literalAttribute.literal[1]]],
222
- }));
221
+ .toBe(JSON.stringify([[literalAttribute.literal[0], literalAttribute.literal[1]], 'endTime']));
223
222
  });
224
223
  it('by literal field - not found', () => {
225
224
  const literalAttribute = { attribute: 'genericField', literal: 'void' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.3.5-beta.2",
3
+ "version": "1.3.5",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -48,4 +48,4 @@
48
48
  "files": [
49
49
  "lib/**/*"
50
50
  ]
51
- }
51
+ }