Fix external patches
This commit is contained in:
parent
84a67bb346
commit
d061f44eda
|
@ -52,10 +52,22 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
|||
const table = await utils.getTableFromSource(source)
|
||||
const { _id, ...rowData } = ctx.request.body
|
||||
|
||||
const dataToUpdate = await inputProcessing(
|
||||
const beforeRow = await sdk.rows.external.getRow(table._id!, _id, {
|
||||
relationships: true,
|
||||
})
|
||||
|
||||
let dataToUpdate = cloneDeep(beforeRow)
|
||||
const allowedField = utils.getSourceFields(source)
|
||||
for (const key of Object.keys(rowData)) {
|
||||
if (!allowedField.includes(key)) continue
|
||||
|
||||
dataToUpdate[key] = rowData[key]
|
||||
}
|
||||
|
||||
dataToUpdate = await inputProcessing(
|
||||
ctx.user?._id,
|
||||
cloneDeep(source),
|
||||
rowData
|
||||
dataToUpdate
|
||||
)
|
||||
|
||||
const validateResult = await sdk.rows.utils.validate({
|
||||
|
@ -66,10 +78,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
|||
throw { validation: validateResult.errors }
|
||||
}
|
||||
|
||||
const beforeRow = await sdk.rows.external.getRow(table._id!, _id, {
|
||||
relationships: true,
|
||||
})
|
||||
|
||||
const response = await handleRequest(Operation.UPDATE, source, {
|
||||
id: breakRowIdField(_id),
|
||||
row: dataToUpdate,
|
||||
|
|
|
@ -110,6 +110,21 @@ function fixBooleanFields(row: Row, table: Table) {
|
|||
return row
|
||||
}
|
||||
|
||||
export function getSourceFields(source: Table | ViewV2): string[] {
|
||||
const isView = sdk.views.isView(source)
|
||||
if (isView) {
|
||||
const fields = Object.keys(
|
||||
helpers.views.basicFields(source, { visible: true })
|
||||
)
|
||||
return fields
|
||||
}
|
||||
|
||||
const fields = Object.entries(source.schema)
|
||||
.filter(([_, field]) => field.visible !== false)
|
||||
.map(([columnName]) => columnName)
|
||||
return fields
|
||||
}
|
||||
|
||||
export async function sqlOutputProcessing(
|
||||
rows: DatasourcePlusQueryResponse,
|
||||
source: Table | ViewV2,
|
||||
|
|
Loading…
Reference in New Issue