@autofleet/sheilta 1.3.4-beta.2 → 1.3.4-hilat-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/formatter/index.d.ts
CHANGED
|
@@ -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;
|
package/lib/formatter/index.js
CHANGED
|
@@ -43,7 +43,13 @@ const formatOrder = ({ order, associationModels = [], }) => order.map((o) => {
|
|
|
43
43
|
const formatPage = page => page || utils_1.PAGE_DEFAULT;
|
|
44
44
|
const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
|
|
45
45
|
const formatInclude = (include, associationsMap = {}) => {
|
|
46
|
-
let formattedInclude = include.map(i =>
|
|
46
|
+
let formattedInclude = include.map((i) => {
|
|
47
|
+
var _a;
|
|
48
|
+
const includedAssociation = associationsMap[i.association || i.model];
|
|
49
|
+
return Object.assign(Object.assign(Object.assign({}, i), { association: includedAssociation, required: i.required !== false }), (i.include && {
|
|
50
|
+
include: formatInclude(i.include, (_a = includedAssociation === null || includedAssociation === void 0 ? void 0 : includedAssociation.target) === null || _a === void 0 ? void 0 : _a.associations),
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
47
53
|
formattedInclude = formattedInclude.map(i => lodash_1.default.omit(i, ['model']));
|
|
48
54
|
return formattedInclude;
|
|
49
55
|
};
|
|
@@ -59,9 +65,9 @@ const formatQuery = (query, associationModels) => {
|
|
|
59
65
|
formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] = queryItemValue;
|
|
60
66
|
return;
|
|
61
67
|
}
|
|
62
|
-
const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels) ?
|
|
69
|
+
utils_1.wrapAttributeWithOperator(queryItemKey) :
|
|
70
|
+
queryItemKey;
|
|
65
71
|
formattedQuery[key] = queryItemValue;
|
|
66
72
|
});
|
|
67
73
|
const formattedScopes = Array.from(formattedScopeMap.entries()).map(([scopeName, scopeValue]) => {
|
|
@@ -91,14 +97,16 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
91
97
|
associationModels,
|
|
92
98
|
});
|
|
93
99
|
const [filteredFormattedOrder, filteredLiteralAttributes] = getAttributeFromOrder(formattedOrder, options);
|
|
100
|
+
// here
|
|
101
|
+
console.log({ attributes });
|
|
94
102
|
const allAttributes = [...filteredLiteralAttributes, ...(attributes || [])];
|
|
95
|
-
const formattedAttribute = allAttributes.length ? { include: allAttributes } : null;
|
|
103
|
+
// const formattedAttribute = allAttributes.length ? { include: allAttributes } : null;
|
|
96
104
|
const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
|
|
97
105
|
const formattedPage = formatPage(page);
|
|
98
106
|
const formattedPerPage = formatPerPage(perPage);
|
|
99
107
|
const result = formatQuery(query, associationModels);
|
|
100
108
|
let { formattedQuery } = result;
|
|
101
|
-
if (searchTerm
|
|
109
|
+
if (searchTerm) {
|
|
102
110
|
const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
|
|
103
111
|
const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
|
|
104
112
|
formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
|
|
@@ -108,6 +116,8 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
108
116
|
],
|
|
109
117
|
};
|
|
110
118
|
}
|
|
111
|
-
|
|
119
|
+
// console.log({ ...(formattedAttribute && { attributes: formattedAttribute }) });
|
|
120
|
+
console.log({ attributes });
|
|
121
|
+
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, (allAttributes && { attributes: allAttributes }));
|
|
112
122
|
};
|
|
113
123
|
exports.default = formatPayload;
|
|
@@ -208,6 +208,7 @@ describe('formatting test', () => {
|
|
|
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: '',
|
|
@@ -215,10 +216,11 @@ describe('formatting test', () => {
|
|
|
215
216
|
}, {
|
|
216
217
|
literalAttributes: [literalAttribute],
|
|
217
218
|
});
|
|
219
|
+
console.log({ attributes });
|
|
218
220
|
expect(JSON.stringify(order)).toBe(JSON.stringify([[`${literalAttribute.attribute} DESC`], ['currencySymbol'], ['id']]));
|
|
219
221
|
expect(JSON.stringify(attributes))
|
|
220
222
|
.toBe(JSON.stringify({
|
|
221
|
-
include: [[literalAttribute.literal[0], literalAttribute.literal[1]]],
|
|
223
|
+
include: [[literalAttribute.literal[0], literalAttribute.literal[1]], 'endTime'],
|
|
222
224
|
}));
|
|
223
225
|
});
|
|
224
226
|
it('by literal field - not found', () => {
|
package/package.json
CHANGED