Fixing issue with updating row validation to allow empty objects.
This commit is contained in:
parent
05e2baa0d3
commit
003b6424a2
|
@ -50,10 +50,10 @@ exports.validate = async ({ appId, tableId, row, table }) => {
|
||||||
const errors = {}
|
const errors = {}
|
||||||
for (let fieldName of Object.keys(table.schema)) {
|
for (let fieldName of Object.keys(table.schema)) {
|
||||||
const constraints = cloneDeep(table.schema[fieldName].constraints)
|
const constraints = cloneDeep(table.schema[fieldName].constraints)
|
||||||
|
const type = table.schema[fieldName].type
|
||||||
// special case for options, need to always allow unselected (null)
|
// special case for options, need to always allow unselected (null)
|
||||||
if (
|
if (
|
||||||
table.schema[fieldName].type ===
|
(type === FieldTypes.OPTIONS || type === FieldTypes.ARRAY) &&
|
||||||
(FieldTypes.OPTIONS || FieldTypes.ARRAY) &&
|
|
||||||
constraints.inclusion
|
constraints.inclusion
|
||||||
) {
|
) {
|
||||||
constraints.inclusion.push(null)
|
constraints.inclusion.push(null)
|
||||||
|
@ -61,17 +61,13 @@ exports.validate = async ({ appId, tableId, row, table }) => {
|
||||||
let res
|
let res
|
||||||
|
|
||||||
// Validate.js doesn't seem to handle array
|
// Validate.js doesn't seem to handle array
|
||||||
if (
|
if (type === FieldTypes.ARRAY && row[fieldName] && row[fieldName].length) {
|
||||||
table.schema[fieldName].type === FieldTypes.ARRAY &&
|
|
||||||
row[fieldName] &&
|
|
||||||
row[fieldName].length
|
|
||||||
) {
|
|
||||||
row[fieldName].map(val => {
|
row[fieldName].map(val => {
|
||||||
if (!constraints.inclusion.includes(val)) {
|
if (!constraints.inclusion.includes(val)) {
|
||||||
errors[fieldName] = "Field not in list"
|
errors[fieldName] = "Field not in list"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (table.schema[fieldName].type === FieldTypes.FORMULA) {
|
} else if (type === FieldTypes.FORMULA) {
|
||||||
res = validateJs.single(
|
res = validateJs.single(
|
||||||
processStringSync(table.schema[fieldName].formula, row),
|
processStringSync(table.schema[fieldName].formula, row),
|
||||||
constraints
|
constraints
|
||||||
|
|
|
@ -81,6 +81,18 @@ const TYPE_TRANSFORM_MAP = {
|
||||||
[FieldTypes.AUTO]: {
|
[FieldTypes.AUTO]: {
|
||||||
parse: () => undefined,
|
parse: () => undefined,
|
||||||
},
|
},
|
||||||
|
[FieldTypes.JSON]: {
|
||||||
|
parse: input => {
|
||||||
|
try {
|
||||||
|
if (input === "") {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return JSON.parse(input)
|
||||||
|
} catch (err) {
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue