improve validation errors

This commit is contained in:
Riccardo Balbo 2024-10-16 19:56:27 +02:00
parent 14b6d7f818
commit ce3ee703df
1 changed files with 4 additions and 4 deletions

View File

@ -752,19 +752,19 @@ export const blinkSchema = object().shape({
apiKey: string() apiKey: string()
.matches(/^blink_[A-Za-z0-9]+$/, { message: 'must match pattern blink_A-Za-z0-9' }) .matches(/^blink_[A-Za-z0-9]+$/, { message: 'must match pattern blink_A-Za-z0-9' })
.when(['apiKeyRecv'], ([apiKeyRecv], schema) => { .when(['apiKeyRecv'], ([apiKeyRecv], schema) => {
if (!apiKeyRecv) return schema.required('required if apiKeyRecv not set') if (!apiKeyRecv) return schema.required('required if api key for receiving not set')
return schema.test({ return schema.test({
test: apiKey => apiKey !== apiKeyRecv, test: apiKey => apiKey !== apiKeyRecv,
message: 'apiKey cannot be the same as apiKeyRecv' message: 'api key for sending cannot be the same as for receiving'
}) })
}), }),
apiKeyRecv: string() apiKeyRecv: string()
.matches(/^blink_[A-Za-z0-9]+$/, { message: 'must match pattern blink_A-Za-z0-9' }) .matches(/^blink_[A-Za-z0-9]+$/, { message: 'must match pattern blink_A-Za-z0-9' })
.when(['apiKey'], ([apiKey], schema) => { .when(['apiKey'], ([apiKey], schema) => {
if (!apiKey) return schema.required('required if apiKey not set') if (!apiKey) return schema.required('required if api key for sending not set')
return schema.test({ return schema.test({
test: apiKeyRecv => apiKeyRecv !== apiKey, test: apiKeyRecv => apiKeyRecv !== apiKey,
message: 'apiKeyRecv cannot be the same as apiKey' message: 'api key for receiving cannot be the same as for sending'
}) })
}), }),
currency: string() currency: string()