@autofleet/sheilta 1.3.2-4 → 1.3.2-6

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.
@@ -11,9 +11,22 @@ declare const formatPayload: ({ order, page, perPage, include, query, attributes
11
11
  perPage?: number;
12
12
  include?: any[];
13
13
  query?: {};
14
- attributes?: any[];
14
+ attributes?: any;
15
15
  searchTerm?: any;
16
16
  }, model?: any, options?: any) => {
17
+ attributes: {
18
+ include: any[];
19
+ };
20
+ query: {};
21
+ order: SequelizeOrder[];
22
+ page: any;
23
+ perPage: any;
24
+ include: any;
25
+ scopes: (string | {
26
+ method: any[];
27
+ })[];
28
+ } | {
29
+ attributes?: undefined;
17
30
  query: {};
18
31
  order: SequelizeOrder[];
19
32
  page: any;
@@ -22,6 +35,5 @@ declare const formatPayload: ({ order, page, perPage, include, query, attributes
22
35
  scopes: (string | {
23
36
  method: any[];
24
37
  })[];
25
- attributes: any[];
26
38
  };
27
39
  export default formatPayload;
@@ -15,7 +15,7 @@ const getAttributeFromOrder = (order, literalAttributes) => {
15
15
  const [formattedOrder, attributes] = order.reduce((acc, o) => {
16
16
  const [item, itemOrder = ASCENDING_KEY] = Array.isArray(o) ? o : [o];
17
17
  const found = literalAttributes === null || literalAttributes === void 0 ? void 0 : literalAttributes.find(obj => obj.attribute === item);
18
- (found ? acc[1] : acc[0]).push(found ? `${found.literal} ${itemOrder}` : o);
18
+ (found ? acc[1] : acc[0]).push(found ? [`${found.literal} ${itemOrder}`] : o);
19
19
  return acc;
20
20
  }, [[], []]);
21
21
  return [formattedOrder, attributes];
@@ -78,14 +78,15 @@ const formatSearchTerm = (searchTerm, attributesToSend, rawAttributes) => ({
78
78
  })),
79
79
  })),
80
80
  });
81
- const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = [], searchTerm = null, }, model, options) => {
81
+ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = null, searchTerm = null, }, model, options) => {
82
82
  const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
83
83
  const formattedOrder = formatOrder({
84
84
  order: [...order, DEFAULT_ORDER],
85
85
  associationModels,
86
86
  });
87
87
  const [filteredFormattedOrder, filteredLiteralAttributes] = getAttributeFromOrder(formattedOrder, options === null || options === void 0 ? void 0 : options.literalAttributes);
88
- const formattedAttribute = [...filteredLiteralAttributes, ...attributes];
88
+ const allAttributes = [...filteredLiteralAttributes, ...(attributes || [])];
89
+ const formattedAttribute = allAttributes.length ? { include: allAttributes } : null;
89
90
  const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
90
91
  const formattedPage = formatPage(page);
91
92
  const formattedPerPage = formatPerPage(perPage);
@@ -101,14 +102,7 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
101
102
  ],
102
103
  };
103
104
  }
104
- return {
105
- query: formattedQuery,
106
- order: filteredFormattedOrder,
107
- page: formattedPage,
108
- perPage: formattedPerPage,
109
- include: formattedInclude,
110
- scopes: result.formattedScopes,
111
- attributes: formattedAttribute,
112
- };
105
+ const selectedAttributes = formattedAttribute ? { attributes: formattedAttribute } : {};
106
+ return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, selectedAttributes);
113
107
  };
114
108
  exports.default = formatPayload;
@@ -201,7 +201,7 @@ describe('formatting test', () => {
201
201
  literalAttributes: [literalAttribute],
202
202
  });
203
203
  expect(JSON.stringify(order)).toBe(JSON.stringify([['id']]));
204
- expect(JSON.stringify(attributes)).toBe(JSON.stringify([`${literalAttribute.literal} ASC`]));
204
+ expect(JSON.stringify(attributes)).toBe(JSON.stringify({ include: [[`${literalAttribute.literal} ASC`]] }));
205
205
  });
206
206
  it('by literal field descending', () => {
207
207
  const literalAttribute = { attribute: 'genericField', literal: 'void' };
@@ -215,7 +215,7 @@ describe('formatting test', () => {
215
215
  literalAttributes: [literalAttribute],
216
216
  });
217
217
  expect(JSON.stringify(order)).toBe(JSON.stringify([['currencySymbol'], ['id']]));
218
- expect(JSON.stringify(attributes)).toBe(JSON.stringify([`${literalAttribute.literal} DESC`]));
218
+ expect(JSON.stringify(attributes)).toBe(JSON.stringify({ include: [[`${literalAttribute.literal} DESC`]] }));
219
219
  });
220
220
  it('by literal field - not found', () => {
221
221
  const literalAttribute = { attribute: 'genericField', literal: 'void' };
@@ -229,7 +229,7 @@ describe('formatting test', () => {
229
229
  literalAttributes: [literalAttribute],
230
230
  });
231
231
  expect(JSON.stringify(order)).toBe(JSON.stringify([[`O${literalAttribute.attribute}`, 'DESC'], ['id']]));
232
- expect(JSON.stringify(attributes)).toBe(JSON.stringify([]));
232
+ expect(JSON.stringify(attributes)).toBe(JSON.stringify(undefined));
233
233
  });
234
234
  });
235
235
  describe('include formatting', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.3.2-4",
3
+ "version": "1.3.2-6",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",