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

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

Loading…
Cancel
Save