express.js 준비
This commit is contained in:
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user