mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Fix nested fields check in validate-payload handler (#7135)
This commit is contained in:
@@ -87,9 +87,11 @@ export function generateJoi(filter: FieldFilter, options?: JoiOptions): AnySchem
|
||||
throw new Error(`[generateJoi] Filter doesn't contain filter rule. Passed filter: ${JSON.stringify(filter)}`);
|
||||
}
|
||||
|
||||
const isField = key.startsWith('_') === false;
|
||||
|
||||
if (isField) {
|
||||
if (Object.keys(value)[0]?.startsWith('_') === false) {
|
||||
schema[key] = Joi.object({
|
||||
[key]: generateJoi(value as FieldFilter, options),
|
||||
});
|
||||
} else {
|
||||
const operator = Object.keys(value)[0];
|
||||
|
||||
if (operator === '_eq') {
|
||||
@@ -183,10 +185,6 @@ export function generateJoi(filter: FieldFilter, options?: JoiOptions): AnySchem
|
||||
const values = Object.values(value)[0] as number[];
|
||||
schema[key] = Joi.number().less(values[0]).greater(values[1]);
|
||||
}
|
||||
} else {
|
||||
schema[key] = Joi.object({
|
||||
[key]: generateJoi(value as FieldFilter, options),
|
||||
});
|
||||
}
|
||||
|
||||
schema[key] = schema[key] ?? Joi.any();
|
||||
|
||||
@@ -27,7 +27,7 @@ export function validatePayload(
|
||||
|
||||
const nestedErrors = flatten<Joi.ValidationError>(
|
||||
subValidation.map((subObj: Record<string, any>) => {
|
||||
return validatePayload(subObj, payload);
|
||||
return validatePayload(subObj, payload, options);
|
||||
})
|
||||
).filter((err?: Joi.ValidationError) => err);
|
||||
|
||||
@@ -36,7 +36,7 @@ export function validatePayload(
|
||||
const subValidation = Object.values(filter)[0] as FieldFilter[];
|
||||
|
||||
const nestedErrors = flatten<Joi.ValidationError>(
|
||||
subValidation.map((subObj: Record<string, any>) => validatePayload(subObj, payload))
|
||||
subValidation.map((subObj: Record<string, any>) => validatePayload(subObj, payload, options))
|
||||
);
|
||||
|
||||
const allErrored = subValidation.length === nestedErrors.length;
|
||||
|
||||
Reference in New Issue
Block a user