Browse Source

fix column validations

Signed-off-by: Vijay Kumar Rathore <professional.vijay8492@gmail.com>
pull/4325/head
Vijay Kumar Rathore 2 years ago
parent
commit
5176047fe3
  1. 16
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

16
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -2236,11 +2236,13 @@ class BaseModelSqlv2 {
for (let i = 0; i < this.model.columns.length; ++i) {
const column = this.model.columns[i];
// skip validation if `validate` is undefined or false
if (!column?.meta?.validate) continue;
if (!column?.meta?.validate && !column?.validate) continue;
const validate = column.getValidators();
const cn = column.column_name;
const columnTitle = column.title;
if (!validate) continue;
const { func, msg } = validate;
for (let j = 0; j < func.length; ++j) {
const fn =
@ -2249,17 +2251,17 @@ class BaseModelSqlv2 {
? customValidators[func[j]]
: Validator[func[j]]
: func[j];
const columnValue = columns?.[cn] || columns?.[columnTitle];
const arg =
typeof func[j] === 'string' ? columns[cn] + '' : columns[cn];
typeof func[j] === 'string' ? columnValue + '' : columnValue;
if (
columns[cn] !== null &&
columns[cn] !== undefined &&
columns[cn] !== '' &&
cn in columns &&
![null, undefined, ''].includes(columnValue) &&
!(fn.constructor.name === 'AsyncFunction' ? await fn(arg) : fn(arg))
) {
NcError.badRequest(
msg[j].replace(/\{VALUE}/g, columns[cn]).replace(/\{cn}/g, cn)
msg[j]
.replace(/\{VALUE}/g, columnValue)
.replace(/\{cn}/g, columnTitle)
);
}
}

Loading…
Cancel
Save