refac: api 시스템 교체
- procDecorator의 타입 복잡도를 낮춤 - 타입 에러가 살짝 더 깔끔함
This commit is contained in:
@@ -4,6 +4,7 @@ import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStruc
|
||||
import { StartSession } from "../ProcDecorator/StartSession";
|
||||
import { IsString } from "class-validator";
|
||||
import { delay } from "../../util/delay";
|
||||
import { declProcDecorators } from "../ProcDecorator/base";
|
||||
|
||||
type BaseAPI = typeof structure.Login.LoginByID;
|
||||
type RType = ExtractResponse<BaseAPI>;
|
||||
@@ -15,19 +16,20 @@ class ArgValidator implements QType {
|
||||
@IsString()
|
||||
password!: string;
|
||||
}
|
||||
const procDecorator = [
|
||||
StartSession,
|
||||
] as const;
|
||||
|
||||
export const LoginByID = POST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||
async (query, ctx, req, res) => {
|
||||
export const LoginByID = POST<RType, EType, QType>
|
||||
(ArgValidator)
|
||||
(declProcDecorators([
|
||||
StartSession,
|
||||
] as const))
|
||||
(async (query, ctx, req, res) => {
|
||||
const username = query.username;
|
||||
const password = query.password;
|
||||
|
||||
//TODO: DB에서 뭔가 가져와야 함
|
||||
await delay(1);
|
||||
|
||||
if(Math.random() < 0.3){
|
||||
if (Math.random() < 0.3) {
|
||||
return {
|
||||
result: false,
|
||||
reason: "로그인 실패",
|
||||
@@ -35,7 +37,7 @@ export const LoginByID = POST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||
}
|
||||
}
|
||||
|
||||
if(Math.random() < 0.5){
|
||||
if (Math.random() < 0.5) {
|
||||
return {
|
||||
result: false,
|
||||
reason: "OTP 인증 필요",
|
||||
@@ -51,5 +53,4 @@ export const LoginByID = POST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||
result: true,
|
||||
nextToken,
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user