Skip to content

Commit 17ca46c

Browse files
author
Petr Kachanovsky
committed
fix: add required field normalization
1 parent 91396a7 commit 17ca46c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adminforth/modules/configValidator.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,22 @@ export default class ConfigValidator implements IConfigValidator {
331331
errors.push(`Resource "${res.resourceId}" column "${col.name}" showIn must be an array`);
332332
}
333333

334-
// check col.required is string or object
335-
if (col.required && !((typeof col.required === 'boolean') || (typeof col.required === 'object'))) {
336-
errors.push(`Resource "${res.resourceId}" column "${col.name}" required must be a string or object`);
334+
// check col.required is boolean or object
335+
if (inCol.required && !((typeof inCol.required === 'boolean') || (typeof inCol.required === 'object'))) {
336+
errors.push(`Resource "${res.resourceId}" column "${col.name}" required must be a boolean or object`);
337337
}
338338

339339
// if it is object check the keys are one of ['create', 'edit']
340-
if (typeof col.required === 'object') {
341-
const wrongRequiredOn = Object.keys(col.required).find((c) => !['create', 'edit'].includes(c));
340+
if (typeof inCol.required === 'object') {
341+
const wrongRequiredOn = Object.keys(inCol.required).find((c) => !['create', 'edit'].includes(c));
342342
if (wrongRequiredOn) {
343-
errors.push(`Resource "${res.resourceId}" column "${col.name}" has invalid required value "${wrongRequiredOn}", allowed keys are 'create', 'edit']`);
343+
errors.push(`Resource "${res.resourceId}" column "${inCol.name}" has invalid required value "${wrongRequiredOn}", allowed keys are 'create', 'edit']`);
344344
}
345345
}
346346

347+
// force required to be object
348+
col.required = typeof inCol.required === 'boolean' ? { create: inCol.required, edit: inCol.required } : inCol.required;
349+
347350
// same for editingNote
348351
if (col.editingNote && !((typeof col.editingNote === 'string') || (typeof col.editingNote === 'object'))) {
349352
errors.push(`Resource "${res.resourceId}" column "${col.name}" editingNote must be a string or object`);

0 commit comments

Comments
 (0)