PR comments
This commit is contained in:
parent
34b6581aed
commit
2b61172fe8
|
@ -54,6 +54,7 @@ export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
|||
type: columnType,
|
||||
subtype: columnSubtype,
|
||||
autocolumn: isAutoColumn,
|
||||
constraints,
|
||||
} = schema[columnName] || {}
|
||||
|
||||
// If the column had an invalid value we don't want to override it
|
||||
|
@ -61,6 +62,12 @@ export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
|||
return
|
||||
}
|
||||
|
||||
const isRequired =
|
||||
!!constraints &&
|
||||
((typeof constraints.presence !== "boolean" &&
|
||||
!constraints.presence?.allowEmpty) ||
|
||||
constraints.presence === true)
|
||||
|
||||
// If the columnType is not a string, then it's not present in the schema, and should be added to the invalid columns array
|
||||
if (typeof columnType !== "string") {
|
||||
results.invalidColumns.push(columnName)
|
||||
|
@ -94,7 +101,7 @@ export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
|||
} else if (
|
||||
(columnType === FieldType.BB_REFERENCE ||
|
||||
columnType === FieldType.BB_REFERENCE_SINGLE) &&
|
||||
!isValidBBReference(columnData, columnType, columnSubtype)
|
||||
!isValidBBReference(columnData, columnType, columnSubtype, isRequired)
|
||||
) {
|
||||
results.schemaValidation[columnName] = false
|
||||
} else {
|
||||
|
@ -170,7 +177,8 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
|
|||
function isValidBBReference(
|
||||
data: any,
|
||||
type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE,
|
||||
subtype: BBReferenceFieldSubType
|
||||
subtype: BBReferenceFieldSubType,
|
||||
isRequired: boolean
|
||||
): boolean {
|
||||
if (typeof data !== "string") {
|
||||
return false
|
||||
|
@ -178,7 +186,7 @@ function isValidBBReference(
|
|||
|
||||
if (type === FieldType.BB_REFERENCE_SINGLE) {
|
||||
if (!data) {
|
||||
return true
|
||||
return !isRequired
|
||||
}
|
||||
const user = parseCsvExport<{ _id: string }>(data)
|
||||
return db.isGlobalUserID(user._id)
|
||||
|
|
Loading…
Reference in New Issue