-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support
Description
Runtime
node.js
Runtime version
22.14
Module version
17.10
Used with
No response
Any other relevant information
I want to check value in array with custom message and next take this error, but array function seems rewrites inner errors and i just take 2 errors like array.includes and array.includesRequiredUnknowns
I tried it with helpers.message as in example and helpers.error with .messages() description
I also tried remove .required and .length() and error also was of part array
Maybe i make some errors or array object always makes this but how to achieve the expected behavior?
How can we help?
export default function (fileDate) {
return Joi.array()
.items(
Joi.number().integer().min(1).required(),
Joi.string()
.pattern(/^\d+-\d+$/)
.required(),
Joi.string()
.pattern(/^\d{2}\.\d{2}\.\d{4}$/)
.required()
.custom((value, helpers) => {
const [day, month, year] = value.split('.');
const date = new Date(`${year}-${month}-${day}`);
if (moment(date).isAfter(moment(fileDate, 'DD.MM.YYYY').subtract(13, 'days'))) {
return helpers.message({
custom: `Validated orders need 2 weeks to be valid, file actual date is ${fileDate}, date order is ${value}`
});
}
return date.toString() === 'Invalid Date'
? helpers.message({ custom: `Incorrect date format: "${value}"` })
: value;
})
)
.length(3);
}
Metadata
Metadata
Assignees
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support