@autofleet/sheilta 1.3.4-beta.2 → 1.3.4
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 +0 -1
- package/lib/formatter/index.js +11 -5
- package/package.json +1 -1
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[];
|
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]) => {
|
|
@@ -98,7 +104,7 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
98
104
|
const formattedPerPage = formatPerPage(perPage);
|
|
99
105
|
const result = formatQuery(query, associationModels);
|
|
100
106
|
let { formattedQuery } = result;
|
|
101
|
-
if (searchTerm
|
|
107
|
+
if (searchTerm) {
|
|
102
108
|
const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
|
|
103
109
|
const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
|
|
104
110
|
formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
|