import { POST } from "../defs"; import type { structure } from "../../apiStructure/sammoRootAPI"; import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs"; 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; type EType = ExtractError; type QType = ExtractQuery; class ArgValidator implements QType { @IsString() username!: string; @IsString() password!: string; } export const LoginByID = POST (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) { return { result: false, reason: "로그인 실패", reqOTP: false, } } if (Math.random() < 0.5) { return { result: false, reason: "OTP 인증 필요", reqOTP: true, } } const userID = 1; const nextToken: [number, string] = [1, "1234567890"]; await ctx.setValue("userID", userID); return { result: true, nextToken, } });