From d981ad039d30f30d68a6a08450e1b03dbb3371b6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 18 Jul 2023 13:40:34 +0200 Subject: [PATCH] Typings --- packages/server/src/api/controllers/row/external.ts | 2 ++ packages/server/src/api/controllers/row/index.ts | 11 +++++++---- packages/server/src/api/controllers/row/internal.ts | 3 +-- packages/server/src/sdk/app/rows/search.ts | 4 +++- packages/types/src/api/web/app/index.ts | 1 + packages/types/src/api/web/app/rows.ts | 3 +++ 6 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 packages/types/src/api/web/app/rows.ts diff --git a/packages/server/src/api/controllers/row/external.ts b/packages/server/src/api/controllers/row/external.ts index 2122ada068..6bae6afd48 100644 --- a/packages/server/src/api/controllers/row/external.ts +++ b/packages/server/src/api/controllers/row/external.ts @@ -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, } } diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 46c933da07..d3c4215182 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -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(() => 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) { const { viewId } = ctx.params const view = await sdk.views.get(viewId) + if (!view) { + ctx.throw(404) + } const tableId = view.tableId ctx.status = 200 diff --git a/packages/server/src/api/controllers/row/internal.ts b/packages/server/src/api/controllers/row/internal.ts index 0367346832..d56ba3f14a 100644 --- a/packages/server/src/api/controllers/row/internal.ts +++ b/packages/server/src/api/controllers/row/internal.ts @@ -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, { diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index 87a1662a54..0a4886278a 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -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) } diff --git a/packages/types/src/api/web/app/index.ts b/packages/types/src/api/web/app/index.ts index bb9eb09abc..5d12a31903 100644 --- a/packages/types/src/api/web/app/index.ts +++ b/packages/types/src/api/web/app/index.ts @@ -1,3 +1,4 @@ export * from "./backup" export * from "./datasource" export * from "./view" +export * from "./rows" diff --git a/packages/types/src/api/web/app/rows.ts b/packages/types/src/api/web/app/rows.ts new file mode 100644 index 0000000000..d40d2ee15d --- /dev/null +++ b/packages/types/src/api/web/app/rows.ts @@ -0,0 +1,3 @@ +export interface SearchResponse { + rows: any[] +}