대충이런느낌
This commit is contained in:
@@ -1,24 +1,55 @@
|
||||
import { POST } from "../defs";
|
||||
import { POST, ngPOST } 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";
|
||||
|
||||
type BaseAPI = typeof structure.Login.LoginByID;
|
||||
type RType = ExtractResponse<BaseAPI>;
|
||||
type EType = ExtractError<BaseAPI>;
|
||||
type QType = ExtractQuery<BaseAPI>;
|
||||
|
||||
class Q implements QType {
|
||||
class ArgValidator implements QType {
|
||||
@IsString()
|
||||
username!: string;
|
||||
@IsString()
|
||||
password!: string;
|
||||
}
|
||||
const procDecorator = [
|
||||
StartSession,
|
||||
] as const;
|
||||
|
||||
const procDecorator = [] as const;
|
||||
export const LoginByID = ngPOST<RType, EType, QType>(ArgValidator)(procDecorator)(
|
||||
async (query, ctx, req, res) => {
|
||||
const username = query.username;
|
||||
const password = query.password;
|
||||
|
||||
export class LoginByID extends POST<RType, EType, QType, typeof procDecorator>{
|
||||
readonly argValidator = Q;
|
||||
readonly procDecorator = procDecorator;
|
||||
protected LoginByID = Symbol("LoginByID");//TODO: remove this
|
||||
protected override async api(query: QType, ctx,): Promise<RType | EType | true> {
|
||||
throw new Error("Method not implemented.");
|
||||
//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,
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user