fix(striker-ui-api): allow async callback in GET request builder

main
Tsu-ba-me 2 years ago
parent f075e219de
commit 66b02d4a77
  1. 14
      striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts
  2. 2
      striker-ui-api/src/types/BuildQueryFunction.d.ts

@ -6,7 +6,7 @@ import { stderr, stdout, stdoutVar } from '../shell';
const buildGetRequestHandler =
(
sqlscript: string | BuildQueryFunction,
scriptOrCallback: string | BuildQueryFunction,
{ beforeRespond }: BuildGetRequestHandlerOptions = {},
) =>
async (request: Request, response: Response) => {
@ -17,12 +17,12 @@ const buildGetRequestHandler =
let result: (number | null | string)[][];
try {
result = await query(
call<string>(sqlscript, {
parameters: [request, buildQueryOptions],
notCallableReturn: sqlscript,
}),
);
const sqlscript: string =
typeof scriptOrCallback === 'function'
? await scriptOrCallback(request, buildQueryOptions)
: scriptOrCallback;
result = await query(sqlscript);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);

@ -7,4 +7,4 @@ type BuildQueryOptions = {
type BuildQueryFunction = (
request: import('express').Request,
options?: BuildQueryOptions,
) => string;
) => string | Promise<string>;

Loading…
Cancel
Save