리팩토링
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ngGET } from "../defs";
|
import { GET } from "../defs";
|
||||||
import type { structure } from "../../apiStructure/sammoRootAPI";
|
import type { structure } from "../../apiStructure/sammoRootAPI";
|
||||||
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ type QType = ExtractQuery<BaseAPI>;
|
|||||||
const argValidator = undefined;
|
const argValidator = undefined;
|
||||||
const procDecorator = [] as const;
|
const procDecorator = [] as const;
|
||||||
|
|
||||||
export const ReqNonce = ngGET<RType, EType, QType>(argValidator)(procDecorator)(
|
export const ReqNonce = GET<RType, EType, QType>(argValidator)(procDecorator)(
|
||||||
(query, ctx, req, res) => {
|
(query, ctx, req, res) => {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ngPOST } from "../defs";
|
import { POST } from "../defs";
|
||||||
import type { structure } from "../../apiStructure/sammoRootAPI";
|
import type { structure } from "../../apiStructure/sammoRootAPI";
|
||||||
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
||||||
import { StartSession } from "../ProcDecorator/StartSession";
|
import { StartSession } from "../ProcDecorator/StartSession";
|
||||||
@@ -19,7 +19,7 @@ const procDecorator = [
|
|||||||
StartSession,
|
StartSession,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const LoginByID = ngPOST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
export const LoginByID = POST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||||
async (query, ctx, req, res) => {
|
async (query, ctx, req, res) => {
|
||||||
const username = query.username;
|
const username = query.username;
|
||||||
const password = query.password;
|
const password = query.password;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ngPOST } from "../defs";
|
import { POST } from "../defs";
|
||||||
import type { structure } from "../../apiStructure/sammoRootAPI";
|
import type { structure } from "../../apiStructure/sammoRootAPI";
|
||||||
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
||||||
import { StartSession } from "../ProcDecorator/StartSession";
|
import { StartSession } from "../ProcDecorator/StartSession";
|
||||||
@@ -18,7 +18,7 @@ const procDecorator = [
|
|||||||
StartSession,
|
StartSession,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const LoginByToken = ngPOST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
export const LoginByToken = POST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||||
async (query, ctx) => {
|
async (query, ctx) => {
|
||||||
query.hashedToken;
|
query.hashedToken;
|
||||||
ctx.clearSession();
|
ctx.clearSession();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type APINamespaceType, ngGET } from "../defs";
|
import { type APINamespaceType, GET as GET } from "../defs";
|
||||||
import type { structure } from "../../apiStructure/sammoRootAPI";
|
import type { structure } from "../../apiStructure/sammoRootAPI";
|
||||||
import type { DefAPINamespace, ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
import type { DefAPINamespace, ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
||||||
import { StartSession } from "../ProcDecorator/StartSession";
|
import { StartSession } from "../ProcDecorator/StartSession";
|
||||||
@@ -12,7 +12,7 @@ const procDecorator = [
|
|||||||
StartSession,
|
StartSession,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const ReqNonce = ngGET<RType, EType, QType>(argValidator)(procDecorator)(
|
export const ReqNonce = GET<RType, EType, QType>(argValidator)(procDecorator)(
|
||||||
async (query, ctx) => {
|
async (query, ctx) => {
|
||||||
const nonce = await ctx.getValue<string>("nonce");
|
const nonce = await ctx.getValue<string>("nonce");
|
||||||
if(nonce !== undefined){
|
if(nonce !== undefined){
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ngGET } from "../defs";
|
import { GET } from "../defs";
|
||||||
import type { structure } from "../../apiStructure/sammoRootAPI";
|
import type { structure } from "../../apiStructure/sammoRootAPI";
|
||||||
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs";
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ type RType = ExtractResponse<BaseAPI>;
|
|||||||
type EType = ExtractError<BaseAPI>;
|
type EType = ExtractError<BaseAPI>;
|
||||||
type QType = ExtractQuery<BaseAPI>;
|
type QType = ExtractQuery<BaseAPI>;
|
||||||
|
|
||||||
export const test = ngGET<RType, EType, QType>(undefined)(undefined)(
|
export const test = GET<RType, EType, QType>(undefined)(undefined)(
|
||||||
(query, ctx, req, res) => {
|
(query, ctx, req, res) => {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-22
@@ -29,9 +29,9 @@ export type APINamespace = {
|
|||||||
type ValidatorType<T> = T extends undefined ? undefined : ClassType<T>;
|
type ValidatorType<T> = T extends undefined ? undefined : ClassType<T>;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export type AnyAPIExecuter = ngAPIExecuter<any, any, any, any>;
|
export type AnyAPIExecuter = APIExecuter<any, any, any, any>;
|
||||||
|
|
||||||
interface ngAPIExecuter<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> {
|
interface APIExecuter<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> {
|
||||||
(query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response): Promise<R | E | true>;
|
(query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response): Promise<R | E | true>;
|
||||||
httpMethod: HttpMethod;
|
httpMethod: HttpMethod;
|
||||||
argValidator?: ValidatorType<Q>;
|
argValidator?: ValidatorType<Q>;
|
||||||
@@ -39,35 +39,35 @@ interface ngAPIExecuter<R extends ValidResponse, E extends InvalidResponse, Q ex
|
|||||||
postDecorator: (ProcDecorator<any, any> | undefined)[];
|
postDecorator: (ProcDecorator<any, any> | undefined)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_GET<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_GET<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'get';
|
httpMethod: 'get';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_POST<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_POST<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'post';
|
httpMethod: 'post';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_PUT<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_PUT<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'put';
|
httpMethod: 'put';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_DELETE<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_DELETE<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'delete';
|
httpMethod: 'delete';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_PATCH<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_PATCH<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'patch';
|
httpMethod: 'patch';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface iAPI_HEAD<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends ngAPIExecuter<R, E, Q, PD> {
|
export interface iAPI_HEAD<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain> extends APIExecuter<R, E, Q, PD> {
|
||||||
httpMethod: 'head';
|
httpMethod: 'head';
|
||||||
}
|
}
|
||||||
|
|
||||||
function ngGenerateAPI<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain>(httpMethod: HttpMethod,
|
function generateAPI<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType, PD extends ProcDecoratorChain>(httpMethod: HttpMethod,
|
||||||
argValidator: ValidatorType<Q> | undefined,
|
argValidator: ValidatorType<Q> | undefined,
|
||||||
procDecoratorChain: PD,
|
procDecoratorChain: PD,
|
||||||
callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>,
|
callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>,
|
||||||
): ngAPIExecuter<R, E, Q, PD> {
|
): APIExecuter<R, E, Q, PD> {
|
||||||
const preDecorator: ProcDecorator<any, any>[] = [];
|
const preDecorator: ProcDecorator<any, any>[] = [];
|
||||||
const postDecorator: (ProcDecorator<any, any> | undefined)[] = [];
|
const postDecorator: (ProcDecorator<any, any> | undefined)[] = [];
|
||||||
if (procDecoratorChain) {
|
if (procDecoratorChain) {
|
||||||
@@ -95,10 +95,10 @@ function ngGenerateAPI<R extends ValidResponse, E extends InvalidResponse, Q ext
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngGET<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function GET<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'get',
|
'get',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
@@ -108,10 +108,10 @@ export function ngGET<R extends ValidResponse, E extends InvalidResponse, Q exte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngPOST<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function POST<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'post',
|
'post',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
@@ -121,10 +121,10 @@ export function ngPOST<R extends ValidResponse, E extends InvalidResponse, Q ext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngPUT<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function PUT<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'put',
|
'put',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
@@ -134,10 +134,10 @@ export function ngPUT<R extends ValidResponse, E extends InvalidResponse, Q exte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngDELETE<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function DELETE<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'delete',
|
'delete',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
@@ -147,10 +147,10 @@ export function ngDELETE<R extends ValidResponse, E extends InvalidResponse, Q e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngPATCH<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function PATCH<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'patch',
|
'patch',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
@@ -160,10 +160,10 @@ export function ngPATCH<R extends ValidResponse, E extends InvalidResponse, Q ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ngHEAD<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
export function HEAD<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType>(argValidator?: ValidatorType<Q>) {
|
||||||
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
return <PD extends ProcDecoratorChain>(procDecoratorChain: PD) => {
|
||||||
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
return (callback: (query: Q, ctx: ResolveChain<PD>, expressReq: Request, expressRes: Response) => Promise<R | E | true>) => {
|
||||||
return ngGenerateAPI<R, E, Q, PD>(
|
return generateAPI<R, E, Q, PD>(
|
||||||
'head',
|
'head',
|
||||||
argValidator,
|
argValidator,
|
||||||
procDecoratorChain,
|
procDecoratorChain,
|
||||||
|
|||||||
+48
-46
@@ -64,7 +64,7 @@ async function preCtx<PD extends ProcDecorator<any, any>>(preDecorator: PlainDec
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postCtx<PD extends ProcDecoratorChain>(ctx: ResolveChain<PD>, postDecorator: (undefined|PlainDecorator)[], req: Request, res: Response, index = -1): Promise<[InvalidProc, number] | undefined> {
|
async function postCtx<PD extends ProcDecoratorChain>(ctx: ResolveChain<PD>, postDecorator: (undefined | PlainDecorator)[], req: Request, res: Response, index = -1): Promise<[InvalidProc, number] | undefined> {
|
||||||
if (!postDecorator) {
|
if (!postDecorator) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -137,53 +137,55 @@ async function apiRun(query: object, req: Request, res: Response, api: AnyAPIExe
|
|||||||
|
|
||||||
export function buildAPISystem<N extends APINamespace, Q extends AnyAPIExecuter>(api: N | Q): Router {
|
export function buildAPISystem<N extends APINamespace, Q extends AnyAPIExecuter>(api: N | Q): Router {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
if(typeof api === 'function') {
|
||||||
|
throw 'root api cannot be function';
|
||||||
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(api)) {
|
for (const [key, value] of Object.entries(api)) {
|
||||||
if (typeof value === 'function') {
|
if (typeof value !== 'function') {
|
||||||
const executer = new value() as Q;
|
|
||||||
|
|
||||||
if (!executer.httpMethod) {
|
|
||||||
throw new Error('APIExecuter.reqType is not defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (executer.httpMethod === 'head') {
|
|
||||||
router[executer.httpMethod](key, async (req, res) => {
|
|
||||||
let query: ExtractQuery<Q>;
|
|
||||||
try {
|
|
||||||
query = await parseParam(req, executer.argValidator);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
res.json({
|
|
||||||
result: false,
|
|
||||||
reason: `invalid parameter: ${e}`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await apiRun(query, req, res, executer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
router[executer.httpMethod](key, async (req, res) => {
|
|
||||||
let query: ExtractQuery<Q>;
|
|
||||||
try {
|
|
||||||
query = await parseBody(req, executer.argValidator);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
res.json({
|
|
||||||
result: false,
|
|
||||||
reason: `invalid parameter: ${e}`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await apiRun(query, req, res, executer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
router.use(key, buildAPISystem(value));
|
router.use(key, buildAPISystem(value));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const executer = value;
|
||||||
|
|
||||||
|
if (!executer.httpMethod) {
|
||||||
|
throw new Error('APIExecuter.reqType is not defined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executer.httpMethod === 'get') {
|
||||||
|
router[executer.httpMethod](key, async (req, res) => {
|
||||||
|
let query: ExtractQuery<Q>;
|
||||||
|
try {
|
||||||
|
query = await parseParam(req, executer.argValidator);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.json({
|
||||||
|
result: false,
|
||||||
|
reason: `invalid parameter: ${e}`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await apiRun(query, req, res, executer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
router[executer.httpMethod](key, async (req, res) => {
|
||||||
|
let query: ExtractQuery<Q>;
|
||||||
|
try {
|
||||||
|
query = await parseBody(req, executer.argValidator);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.json({
|
||||||
|
result: false,
|
||||||
|
reason: `invalid parameter: ${e}`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await apiRun(query, req, res, executer);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return router;
|
return router;
|
||||||
|
|||||||
Reference in New Issue
Block a user