Feat add support of limit, offset, order
Allows passing these as query params to list and scope methods.
This commit is contained in:
@ -66,6 +66,11 @@ export const idParamsMethods = [
|
||||
'update',
|
||||
];
|
||||
|
||||
export const restrictMethods = [
|
||||
'list',
|
||||
'scope',
|
||||
];
|
||||
|
||||
export default ({
|
||||
method, attributeValidation, associationValidation, scopes = [], config = {},
|
||||
}) => {
|
||||
@ -74,6 +79,7 @@ export default ({
|
||||
const hasPayload = payloadMethods.includes(method);
|
||||
const hasScopeParams = scopeParamsMethods.includes(method);
|
||||
const hasIdParams = idParamsMethods.includes(method);
|
||||
const hasRestrictMethods = restrictMethods.includes(method);
|
||||
// clone the config so we don't modify it on multiple passes.
|
||||
let methodConfig = { ...config, validate: { ...config.validate } };
|
||||
|
||||
@ -133,5 +139,18 @@ export default ({
|
||||
methodConfig = set(methodConfig, 'validate.params', params);
|
||||
}
|
||||
|
||||
if (hasRestrictMethods) {
|
||||
const query = concatToJoiObject(joi.object()
|
||||
.keys({
|
||||
limit: joi.number().min(0).integer(),
|
||||
offset: joi.number().min(0).integer(),
|
||||
order: joi.array(),
|
||||
}),
|
||||
get(methodConfig, 'validate.query')
|
||||
);
|
||||
|
||||
methodConfig = set(methodConfig, 'validate.query', query);
|
||||
}
|
||||
|
||||
return methodConfig;
|
||||
};
|
||||
|
Reference in New Issue
Block a user