More types
This commit is contained in:
parent
f0f68f10d8
commit
af933bd158
|
@ -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)
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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",
|
||||
})
|
||||
|
|
|
@ -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 {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue