@autofleet/sheilta 1.4.1 → 1.4.2
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/middleware/index.js
CHANGED
|
@@ -25,10 +25,11 @@ const querySchema = joi_1.object({
|
|
|
25
25
|
perPage: joi_1.number(),
|
|
26
26
|
include: joi_1.array().items(joi_1.any()),
|
|
27
27
|
searchTerm: joi_1.string(),
|
|
28
|
+
group: joi_1.array().items(joi_1.string()),
|
|
28
29
|
enrichments: joi_1.array().items(joi_1.string()),
|
|
29
30
|
});
|
|
30
31
|
exports.newQueryValidationMiddleware = (inner = 'body') => (model, options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
const { query, attributes, order, page, perPage, include, enrichments, } = req[inner];
|
|
32
|
+
const { query, attributes, order, page, perPage, include, group, enrichments, } = req[inner];
|
|
32
33
|
try {
|
|
33
34
|
const result = querySchema.validate(req[inner]);
|
|
34
35
|
if (result.error) {
|
|
@@ -42,6 +43,7 @@ exports.newQueryValidationMiddleware = (inner = 'body') => (model, options = {})
|
|
|
42
43
|
perPage,
|
|
43
44
|
include,
|
|
44
45
|
enrichments,
|
|
46
|
+
group,
|
|
45
47
|
}, model, options);
|
|
46
48
|
return next();
|
|
47
49
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MiddlewareValidationOption } from '../middleware';
|
|
2
|
-
export declare const validatePayload: ({ query, order, attributes, include, page, perPage, enrichments, }: {
|
|
2
|
+
export declare const validatePayload: ({ query, order, attributes, include, page, perPage, enrichments, group, }: {
|
|
3
3
|
query?: {};
|
|
4
4
|
order?: any[];
|
|
5
5
|
attributes?: any[];
|
|
@@ -7,4 +7,5 @@ export declare const validatePayload: ({ query, order, attributes, include, page
|
|
|
7
7
|
page?: number;
|
|
8
8
|
perPage?: number;
|
|
9
9
|
enrichments?: any[];
|
|
10
|
+
group?: any[];
|
|
10
11
|
}, model?: any, options?: MiddlewareValidationOption) => boolean;
|
package/lib/validations/index.js
CHANGED
|
@@ -103,7 +103,7 @@ const validateIncludePayload = (include, associations) => {
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
};
|
|
106
|
-
exports.validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, enrichments = [], }, model, options = {}) => {
|
|
106
|
+
exports.validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, enrichments = [], group = [], }, model, options = {}) => {
|
|
107
107
|
const rawAttributes = Object.keys(model.rawAttributes);
|
|
108
108
|
const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
|
|
109
109
|
if (!attributes || attributes.length === 0) {
|
|
@@ -116,6 +116,9 @@ exports.validatePayload = ({ query = {}, order = [], attributes = [], include =
|
|
|
116
116
|
validateOrderAttributes(order, rawAttributes, associationModels, options);
|
|
117
117
|
validateQueryPayload(query, rawAttributes, associationModels);
|
|
118
118
|
validateEnrichments(enrichments, options);
|
|
119
|
+
if (!Array.isArray(group)) {
|
|
120
|
+
utils_1.throwBadRequestError('group must be an array');
|
|
121
|
+
}
|
|
119
122
|
if (include.length && typeof include === 'object') {
|
|
120
123
|
validateIncludePayload(include, model === null || model === void 0 ? void 0 : model.associations);
|
|
121
124
|
}
|