From 623b385d8a60df20993eb02211663cbbbb368c30 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Sep 2024 17:53:25 +0200 Subject: [PATCH] Promisify middleware --- .../src/middleware/triggerRowActionAuthorised.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/server/src/middleware/triggerRowActionAuthorised.ts b/packages/server/src/middleware/triggerRowActionAuthorised.ts index 6a3d1e3a5d..2f94e46589 100644 --- a/packages/server/src/middleware/triggerRowActionAuthorised.ts +++ b/packages/server/src/middleware/triggerRowActionAuthorised.ts @@ -5,16 +5,24 @@ import { docIds } from "@budibase/backend-core" import * as utils from "../db/utils" import sdk from "../sdk" +async function executeMiddleware( + ctx: UserCtx, + delegate: (ctx: UserCtx, next: any) => any +) { + await new Promise(r => delegate(ctx, () => r())) +} + export function triggerRowActionAuthorised( sourcePath: string, actionPath: string ) { - function extractResourceIds(ctx: UserCtx) { + async function extractResourceIds(ctx: UserCtx) { ctx = { ...ctx } // Reusing the existing middleware to extract the value - paramSubResource(sourcePath, actionPath)(ctx, () => {}) + await executeMiddleware(ctx, paramSubResource(sourcePath, actionPath)) - const { resourceId: sourceId, subResourceId: rowActionId } = ctx + const sourceId: string = ctx.resourceId + const rowActionId: String = ctx.subResourceId const isTableId = docIds.isTableId(sourceId) const isViewId = utils.isViewID(sourceId)