This commit is contained in:
Adria Navarro 2024-08-29 12:16:44 +02:00
parent 6b259676b2
commit d75f1debda
6 changed files with 21 additions and 10 deletions

View File

@ -71,8 +71,9 @@ export async function patch(
}
export const save = async (ctx: UserCtx<Row, Row>) => {
const appId = ctx.appId
const { tableId } = utils.getSourceId(ctx)
const { sourceId } = ctx.params
const appId = ctx.appId
const body = ctx.request.body
// user metadata doesn't exist yet - don't allow creation
@ -85,9 +86,9 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
return patch(ctx as UserCtx<PatchRowRequest, PatchRowResponse>)
}
const { row, table, squashed } = tableId.includes("datasource_plus")
? await sdk.rows.save(tableId, ctx.request.body, ctx.user?._id)
? await sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id)
: await quotas.addRow(() =>
sdk.rows.save(tableId, ctx.request.body, ctx.user?._id)
sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id)
)
ctx.status = 200
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)

View File

@ -123,7 +123,11 @@ export async function updateAllFormulasInTable(table: Table) {
export async function finaliseRow(
table: Table,
row: Row,
{ oldTable, updateFormula }: { oldTable?: Table; updateFormula: boolean } = {
{
oldTable,
updateFormula,
fromViewId,
}: { oldTable?: Table; updateFormula: boolean; fromViewId?: string } = {
updateFormula: true,
}
) {
@ -154,6 +158,8 @@ export async function finaliseRow(
if (updateFormula) {
await updateRelatedFormula(table, enrichedRow)
}
const squashed = await linkRows.squashLinks(table, enrichedRow)
const squashed = await linkRows.squashLinks(table, enrichedRow, {
fromViewId,
})
return { row: enrichedRow, squashed, table }
}

View File

@ -2618,7 +2618,7 @@ describe.each([
return rows.find(r => r._id === row._id!)
},
],
// ["from original saved row", (row: Row) => row],
["from original saved row", (row: Row) => row],
]
it.each(testScenarios)(

View File

@ -27,10 +27,11 @@ export async function getRow(
}
export async function save(
tableId: string,
tableOrViewId: string,
inputs: Row,
userId: string | undefined
) {
const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId)
const table = await sdk.tables.getTable(tableId)
const { table: updatedTable, row } = await inputProcessing(
userId,
@ -64,6 +65,7 @@ export async function save(
row: await outputProcessing(table, row, {
preserveLinks: true,
squash: true,
fromViewId: viewId,
}),
}
} else {

View File

@ -13,10 +13,11 @@ import { getFullUser } from "../../../utilities/users"
import { tryExtractingTableAndViewId } from "./utils"
export async function save(
tableId: string,
tableOrViewId: string,
inputs: Row,
userId: string | undefined
) {
const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId)
inputs.tableId = tableId
if (!inputs._rev && !inputs._id) {
@ -51,6 +52,7 @@ export async function save(
return finaliseRow(table, row, {
oldTable: dbTable,
updateFormula: true,
fromViewId: viewId,
})
}

View File

@ -37,11 +37,11 @@ function pickApi(tableOrViewId: string) {
}
export async function save(
tableId: string,
tableOrViewId: string,
row: Row,
userId: string | undefined
) {
return pickApi(tableId).save(tableId, row, userId)
return pickApi(tableOrViewId).save(tableOrViewId, row, userId)
}
export async function find(tableOrViewId: string, rowId: string) {