Merge branch 'master' into BUDI-7656/add-migration
This commit is contained in:
commit
0728221379
2 changed files with 54 additions and 2 deletions
|
@ -25,6 +25,7 @@ import {
|
||||||
outputProcessing,
|
outputProcessing,
|
||||||
} from "../../../utilities/rowProcessor"
|
} from "../../../utilities/rowProcessor"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
|
import { generateIdForRow } from "./utils"
|
||||||
|
|
||||||
export async function handleRequest<T extends Operation>(
|
export async function handleRequest<T extends Operation>(
|
||||||
operation: T,
|
operation: T,
|
||||||
|
@ -55,11 +56,19 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
||||||
throw { validation: validateResult.errors }
|
throw { validation: validateResult.errors }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const beforeRow = await sdk.rows.external.getRow(tableId, _id, {
|
||||||
|
relationships: true,
|
||||||
|
})
|
||||||
|
|
||||||
const response = await handleRequest(Operation.UPDATE, tableId, {
|
const response = await handleRequest(Operation.UPDATE, tableId, {
|
||||||
id: breakRowIdField(_id),
|
id: breakRowIdField(_id),
|
||||||
row: dataToUpdate,
|
row: dataToUpdate,
|
||||||
})
|
})
|
||||||
const row = await sdk.rows.external.getRow(tableId, _id, {
|
|
||||||
|
// The id might have been changed, so the refetching would fail. Recalculating the id just in case
|
||||||
|
const updatedId =
|
||||||
|
generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id
|
||||||
|
const row = await sdk.rows.external.getRow(tableId, updatedId, {
|
||||||
relationships: true,
|
relationships: true,
|
||||||
})
|
})
|
||||||
const enrichedRow = await outputProcessing(table, row, {
|
const enrichedRow = await outputProcessing(table, row, {
|
||||||
|
|
|
@ -38,7 +38,7 @@ describe.each([
|
||||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||||
])("/rows (%s)", (__, dsProvider) => {
|
])("/rows (%s)", (providerType, dsProvider) => {
|
||||||
const isInternal = dsProvider === undefined
|
const isInternal = dsProvider === undefined
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
|
|
||||||
|
@ -693,6 +693,49 @@ describe.each([
|
||||||
})
|
})
|
||||||
expect(resp.relationship.length).toBe(1)
|
expect(resp.relationship.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
!isInternal &&
|
||||||
|
// TODO: SQL is having issues creating composite keys
|
||||||
|
providerType !== DatabaseName.SQL_SERVER &&
|
||||||
|
it("should support updating fields that are part of a composite key", async () => {
|
||||||
|
const tableRequest = saveTableRequest({
|
||||||
|
primary: ["number", "string"],
|
||||||
|
schema: {
|
||||||
|
string: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "string",
|
||||||
|
},
|
||||||
|
number: {
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
name: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
delete tableRequest.schema.id
|
||||||
|
|
||||||
|
const table = await config.api.table.save(tableRequest)
|
||||||
|
|
||||||
|
const stringValue = generator.word()
|
||||||
|
const naturalValue = generator.integer({ min: 0, max: 1000 })
|
||||||
|
|
||||||
|
const existing = await config.api.row.save(table._id!, {
|
||||||
|
string: stringValue,
|
||||||
|
number: naturalValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(existing._id).toEqual(`%5B${naturalValue}%2C'${stringValue}'%5D`)
|
||||||
|
|
||||||
|
const row = await config.api.row.patch(table._id!, {
|
||||||
|
_id: existing._id!,
|
||||||
|
_rev: existing._rev!,
|
||||||
|
tableId: table._id!,
|
||||||
|
string: stringValue,
|
||||||
|
number: 1500,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(row._id).toEqual(`%5B${"1500"}%2C'${stringValue}'%5D`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
|
|
Loading…
Reference in a new issue