@autofleet/sheilta 1.2.8 → 1.2.9-beta
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 +1 -1
- package/lib/formatter/index.js +17 -17
- package/package.json +1 -1
package/lib/formatter/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare type FormatPayloadOptions = {
|
|
|
4
4
|
includeRawPayload?: boolean;
|
|
5
5
|
};
|
|
6
6
|
declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
|
|
7
|
-
order
|
|
7
|
+
order?: any[];
|
|
8
8
|
page?: number;
|
|
9
9
|
perPage?: number;
|
|
10
10
|
include?: any[];
|
package/lib/formatter/index.js
CHANGED
|
@@ -5,22 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const DEFAULT_ORDER = 'id';
|
|
8
9
|
const DESCENDING_KEY = 'DESC';
|
|
9
|
-
const formatOrder = ({ order
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}));
|
|
10
|
+
const formatOrder = ({ order, associationModels = [], }) => order.map((o) => {
|
|
11
|
+
const formattedOrder = [utils_1.extractAttributeNameFromOrder(o, associationModels)];
|
|
12
|
+
const isOrderDescOrder = utils_1.isOrderDesc(o);
|
|
13
|
+
const isOrderAssociation = utils_1.isAttributeByAssociation(isOrderDescOrder
|
|
14
|
+
? o.split(utils_1.ORDER_PREFIX)[1]
|
|
15
|
+
: o, associationModels);
|
|
16
|
+
if (isOrderAssociation) {
|
|
17
|
+
formattedOrder.push(utils_1.extractAssociatedAttributeNameFromOrder(o));
|
|
18
|
+
}
|
|
19
|
+
if (isOrderDescOrder) {
|
|
20
|
+
formattedOrder.push(DESCENDING_KEY);
|
|
21
|
+
}
|
|
22
|
+
return formattedOrder;
|
|
23
|
+
});
|
|
24
24
|
const formatPage = page => page || utils_1.PAGE_DEFAULT;
|
|
25
25
|
const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
|
|
26
26
|
const formatInclude = (include, associationsMap = {}) => {
|
|
@@ -39,10 +39,10 @@ const formatSearchTerm = (searchTerm, attributesToSend, rawAttributes) => ({
|
|
|
39
39
|
})),
|
|
40
40
|
})),
|
|
41
41
|
});
|
|
42
|
-
const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = null, searchTerm = null, }, model) => {
|
|
42
|
+
const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = null, searchTerm = null, }, model) => {
|
|
43
43
|
const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
|
|
44
44
|
const formattedOrder = formatOrder({
|
|
45
|
-
order,
|
|
45
|
+
order: [...order, DEFAULT_ORDER],
|
|
46
46
|
associationModels,
|
|
47
47
|
});
|
|
48
48
|
const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
|