1
0
Fork 0
mirror of synced 2024-09-13 07:53:31 +12:00

Save timeonly on external db

This commit is contained in:
Adria Navarro 2024-05-17 15:55:27 +02:00
parent 16e58a38ea
commit a81626005c

View file

@ -1,3 +1,4 @@
import dayjs from "dayjs"
import {
AutoFieldSubType,
AutoReason,
@ -285,13 +286,10 @@ export class ExternalRequest<T extends Operation> {
// parse floats/numbers
if (field.type === FieldType.NUMBER && !isNaN(parseFloat(row[key]))) {
newRow[key] = parseFloat(row[key])
}
// if its not a link then just copy it over
if (field.type !== FieldType.LINK) {
newRow[key] = row[key]
continue
}
const { tableName: linkTableName } = breakExternalTableId(field?.tableId)
} else if (field.type === FieldType.LINK) {
const { tableName: linkTableName } = breakExternalTableId(
field?.tableId
)
// table has to exist for many to many
if (!linkTableName || !this.tables[linkTableName]) {
continue
@ -306,7 +304,8 @@ export class ExternalRequest<T extends Operation> {
if (typeof row[key] === "string") {
id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1]
}
newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0]
newRow[field.foreignKey || linkTablePrimary] =
breakRowIdField(id)[0]
} else {
// Removing from both new and row, as we don't know if it has already been processed
row[field.foreignKey || linkTablePrimary] = null
@ -345,6 +344,15 @@ export class ExternalRequest<T extends Operation> {
})
}
}
} else if (
field.type === FieldType.DATETIME &&
field.timeOnly &&
row[key]
) {
newRow[key] = dayjs(row[key]).format("HH:mm")
} else {
newRow[key] = row[key]
}
}
// we return the relationships that may need to be created in the through table
// we do this so that if the ID is generated by the DB it can be inserted