Fix invalid

This commit is contained in:
Adria Navarro 2024-08-02 13:14:33 +02:00
parent cd1a7699b2
commit e8e4f064a5
1 changed files with 26 additions and 21 deletions

View File

@ -96,6 +96,7 @@ export function validate(
return return
} else if ( } else if (
[FieldType.STRING].includes(columnType) && [FieldType.STRING].includes(columnType) &&
!columnData &&
helpers.schema.isRequired(constraints) helpers.schema.isRequired(constraints)
) { ) {
results.schemaValidation[columnName] = false results.schemaValidation[columnName] = false
@ -215,29 +216,33 @@ function isValidBBReference(
subtype: BBReferenceFieldSubType, subtype: BBReferenceFieldSubType,
isRequired: boolean isRequired: boolean
): boolean { ): boolean {
if (type === FieldType.BB_REFERENCE_SINGLE) { try {
if (!data) { if (type === FieldType.BB_REFERENCE_SINGLE) {
return !isRequired if (!data) {
} return !isRequired
const user = parseJsonExport<{ _id: string }>(data)
return db.isGlobalUserID(user._id)
}
switch (subtype) {
case BBReferenceFieldSubType.USER:
case BBReferenceFieldSubType.USERS: {
const userArray = parseJsonExport<{ _id: string }[]>(data)
if (!Array.isArray(userArray)) {
return false
} }
const user = parseJsonExport<{ _id: string }>(data)
const constainsWrongId = userArray.find( return db.isGlobalUserID(user._id)
user => !db.isGlobalUserID(user._id)
)
return !constainsWrongId
} }
default:
throw utils.unreachable(subtype) switch (subtype) {
case BBReferenceFieldSubType.USER:
case BBReferenceFieldSubType.USERS: {
const userArray = parseJsonExport<{ _id: string }[]>(data)
if (!Array.isArray(userArray)) {
return false
}
const constainsWrongId = userArray.find(
user => !db.isGlobalUserID(user._id)
)
return !constainsWrongId
}
default:
throw utils.unreachable(subtype)
}
} catch {
return false
} }
} }