express.js 준비

This commit is contained in:
2023-08-06 13:53:12 +00:00
parent 691f5e79ce
commit 69de10642e
4 changed files with 20 additions and 36 deletions
+2 -2
View File
@@ -8,8 +8,8 @@ type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
class Q implements QType {
username: string;
password: string;
username!: string;
password!: string;
}
export class LoginByID extends POST<RType, EType, QType>{
readonly argValidator = undefined;
+11 -13
View File
@@ -3,20 +3,18 @@ import type { Request, Response } from 'express';
import type { Callable, DefAPINamespace, DeleteAPICallT, GetAPICallT, HeadAPICallT, HttpMethod, InvalidResponse, PatchAPICallT, PostAPICallT, PutAPICallT, RawArgType, ValidResponse, recoveryMethod } from '../apiStructure/defs';
import {
validate,
validateSync,
validateOrReject,
ValidatorOptions,
} from "class-validator";
import { ClassTransformOptions, plainToInstance } from "class-transformer";
type ValidatorOptions,
} from "class-validator";
import { type ClassTransformOptions, plainToInstance } from "class-transformer";
export type APINamespace = {
[key: string]: APINamespace
| GET<any, any, any>
| POST<any, any, any>
| PUT<any, any, any>
| DELETE<any, any, any>
| PATCH<any, any, any>
| HEAD<any, any, any>
| ClassType<GET<any, any, any>>
| ClassType<POST<any, any, any>>
| ClassType<PUT<any, any, any>>
| ClassType<DELETE<any, any, any>>
| ClassType<PATCH<any, any, any>>
| ClassType<HEAD<any, any, any>>
;
}
@@ -41,7 +39,7 @@ export abstract class APIExecuter<R extends ValidResponse, E extends InvalidResp
export abstract class APIBodyParseExecuter<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType> extends APIExecuter<R, E, Q>{
protected async parseQuery(expressReq: Request): Promise<Q> {
if(!this.argValidator){
if (!this.argValidator) {
return expressReq.body as Q;
}
@@ -59,7 +57,7 @@ export abstract class APIBodyParseExecuter<R extends ValidResponse, E extends In
export abstract class GET<R extends ValidResponse, E extends InvalidResponse, Q extends RawArgType> extends APIExecuter<R, E, Q>{
override readonly reqType = 'get';
protected async parseQuery(expressReq: Request): Promise<Q> {
if(!this.argValidator){
if (!this.argValidator) {
return expressReq.query as Q;
}