This commit is contained in:
Adria Navarro 2023-07-18 13:40:34 +02:00
parent 891ba4148b
commit d981ad039d
6 changed files with 17 additions and 7 deletions

View File

@ -73,9 +73,11 @@ export async function patch(ctx: UserCtx) {
row: inputs,
})
const row = await getRow(tableId, id, { relationships: true })
const table = await sdk.tables.getTable(tableId)
return {
...response,
row,
table,
}
}

View File

@ -2,7 +2,7 @@ import { quotas } from "@budibase/pro"
import * as internal from "./internal"
import * as external from "./external"
import { isExternalTable } from "../../../integrations/utils"
import { Ctx } from "@budibase/types"
import { Ctx, SearchResponse } from "@budibase/types"
import * as utils from "./utils"
import { gridSocket } from "../../../websockets"
import sdk from "../../../sdk"
@ -114,7 +114,7 @@ export async function destroy(ctx: any) {
response = rows
for (let row of rows) {
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
gridSocket?.emitRowDeletion(ctx, row._id)
gridSocket?.emitRowDeletion(ctx, row._id!)
}
} else {
let resp = await quotas.addQuery<any>(() => pickApi(tableId).destroy(ctx), {
@ -124,7 +124,7 @@ export async function destroy(ctx: any) {
response = resp.response
row = resp.row
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
gridSocket?.emitRowDeletion(ctx, row._id)
gridSocket?.emitRowDeletion(ctx, row._id!)
}
ctx.status = 200
// for automations include the row that was deleted
@ -146,9 +146,12 @@ export async function search(ctx: any) {
})
}
export async function searchView(ctx: any) {
export async function searchView(ctx: Ctx<void, SearchResponse>) {
const { viewId } = ctx.params
const view = await sdk.views.get(viewId)
if (!view) {
ctx.throw(404)
}
const tableId = view.tableId
ctx.status = 200

View File

@ -19,7 +19,6 @@ import { UserCtx, LinkDocumentValue, Row, Table } from "@budibase/types"
import sdk from "../../../sdk"
export async function patch(ctx: UserCtx) {
const db = context.getAppDB()
const inputs = ctx.request.body
const tableId = inputs.tableId
const isUserTable = tableId === InternalTables.USER_METADATA
@ -77,7 +76,7 @@ export async function patch(ctx: UserCtx) {
// the row has been updated, need to put it into the ctx
ctx.request.body = row
await userController.updateMetadata(ctx)
return { row: ctx.body, table }
return { row: ctx.body as Row, table }
}
return finaliseRow(table, row, {

View File

@ -30,7 +30,9 @@ function pickApi(tableId: any) {
return internal
}
export async function search(options: SearchParams) {
export async function search(options: SearchParams): Promise<{
rows: any[]
}> {
return pickApi(options.tableId).search(options)
}

View File

@ -1,3 +1,4 @@
export * from "./backup"
export * from "./datasource"
export * from "./view"
export * from "./rows"

View File

@ -0,0 +1,3 @@
export interface SearchResponse {
rows: any[]
}