1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

More types

This commit is contained in:
Adria Navarro 2023-07-26 13:53:35 +02:00
parent f0f68f10d8
commit af933bd158
5 changed files with 33 additions and 22 deletions

View file

@ -8,6 +8,8 @@ import {
Datasource,
IncludeRelationship,
Operation,
PatchRowRequest,
PatchRowResponse,
Row,
Table,
UserCtx,
@ -55,14 +57,12 @@ export async function handleRequest(
)
}
export async function patch(ctx: UserCtx) {
const inputs = ctx.request.body
export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
const tableId = ctx.params.tableId
const id = inputs._id
// don't save the ID to db
delete inputs._id
const { id, ...rowData } = ctx.request.body
const validateResult = await utils.validate({
row: inputs,
row: rowData,
tableId,
})
if (!validateResult.valid) {
@ -70,7 +70,7 @@ export async function patch(ctx: UserCtx) {
}
const response = await handleRequest(Operation.UPDATE, tableId, {
id: breakRowIdField(id),
row: inputs,
row: rowData,
})
const row = await getRow(tableId, id, { relationships: true })
const table = await sdk.tables.getTable(tableId)

View file

@ -15,10 +15,17 @@ import * as utils from "./utils"
import { cloneDeep } from "lodash/fp"
import { context, db as dbCore } from "@budibase/backend-core"
import { finaliseRow, updateRelatedFormula } from "./staticFormula"
import { UserCtx, LinkDocumentValue, Row, Table } from "@budibase/types"
import {
UserCtx,
LinkDocumentValue,
Row,
Table,
PatchRowRequest,
PatchRowResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
export async function patch(ctx: UserCtx) {
export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
const inputs = ctx.request.body
const tableId = inputs.tableId
const isUserTable = tableId === InternalTables.USER_METADATA
@ -27,7 +34,7 @@ export async function patch(ctx: UserCtx) {
let dbTable = await sdk.tables.getTable(tableId)
oldRow = await outputProcessing(
dbTable,
await utils.findRow(ctx, tableId, inputs._id)
await utils.findRow(ctx, tableId, inputs._id!)
)
} catch (err) {
if (isUserTable) {
@ -74,7 +81,7 @@ export async function patch(ctx: UserCtx) {
if (isUserTable) {
// the row has been updated, need to put it into the ctx
ctx.request.body = row
ctx.request.body = row as any
await userController.updateMetadata(ctx)
return { row: ctx.body as Row, table }
}

View file

@ -1,6 +1,5 @@
import { generateUserMetadataID, generateUserFlagID } from "../../db/utils"
import { generateUserFlagID } from "../../db/utils"
import { InternalTables } from "../../db/utils"
import { getGlobalUsers } from "../../utilities/global"
import { getFullUser } from "../../utilities/users"
import { context } from "@budibase/backend-core"
import { Ctx, UserCtx } from "@budibase/types"

View file

@ -16,6 +16,7 @@ import {
FieldType,
SortType,
SortOrder,
PatchRowRequest,
} from "@budibase/types"
import {
expectAnyInternalColsAttributes,
@ -400,9 +401,9 @@ describe("/rows", () => {
const queryUsage = await getQueryUsage()
const res = await config.api.row.patch(table._id!, {
_id: existing._id,
_rev: existing._rev,
tableId: table._id,
_id: existing._id!,
_rev: existing._rev!,
tableId: table._id!,
name: "Updated Name",
})
@ -428,9 +429,9 @@ describe("/rows", () => {
await config.api.row.patch(
table._id!,
{
_id: existing._id,
_rev: existing._rev,
tableId: table._id,
_id: existing._id!,
_rev: existing._rev!,
tableId: table._id!,
name: 1,
},
{ expectStatus: 400 }
@ -451,7 +452,7 @@ describe("/rows", () => {
const [row] = searchResponse.body.rows as Row[]
const res = await config.api.row.patch(table._id!, {
...row,
...(row as PatchRowRequest),
name: "Updated Name",
description: "Updated Description",
})
@ -478,7 +479,7 @@ describe("/rows", () => {
const [row] = searchResponse.body.rows as Row[]
const res = await config.api.row.patch(table._id!, {
...row,
...(row as PatchRowRequest),
name: "Updated Name",
description: "Updated Description",
})

View file

@ -1,6 +1,10 @@
import { Row } from "../../../documents"
export interface PatchRowRequest extends Row {}
export interface PatchRowRequest extends Row {
_id: string
_rev: string
tableId: string
}
export interface PatchRowResponse extends Row {}