refactor: change verify input as frontend cannot detect type

This commit is contained in:
Methapon2001 2025-02-21 10:06:00 +07:00
parent d2d4036bcd
commit 2da138939c

View file

@ -7,13 +7,15 @@ import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
type SendEmail = { type SendEmail = {
identityNumber: string;
email: string; email: string;
} & ({ legalPersonNo: string } | { citizenId: string }); };
type VerificationPayload = { type VerificationPayload = {
identityNumber: string;
email: string; email: string;
otp: string; otp: string;
} & ({ legalPersonNo: string } | { citizenId: string }); };
let emailTransport: ReturnType<(typeof nodemailer)["createTransport"]>; let emailTransport: ReturnType<(typeof nodemailer)["createTransport"]>;
@ -61,19 +63,20 @@ export class verificationController extends Controller {
const dataCustomerBranch = await prisma.customerBranch.findFirst({ const dataCustomerBranch = await prisma.customerBranch.findFirst({
where: { where: {
email: body.email, email: body.email,
...("citizenId" in body OR: [
? { {
citizenId: body.citizenId, citizenId: body.identityNumber,
customer: { customer: {
customerType: "PERS", customerType: "PERS",
}, },
} },
: { {
legalPersonNo: body.legalPersonNo, legalPersonNo: body.identityNumber,
customer: { customer: {
customerType: "CORP", customerType: "CORP",
}, },
}), },
],
}, },
}); });
@ -105,19 +108,20 @@ export class verificationController extends Controller {
const customerBranch = await prisma.customerBranch.findFirst({ const customerBranch = await prisma.customerBranch.findFirst({
where: { where: {
email: body.email, email: body.email,
...("citizenId" in body OR: [
? { {
citizenId: body.citizenId, citizenId: body.identityNumber,
customer: { customer: {
customerType: "PERS", customerType: "PERS",
}, },
} },
: { {
legalPersonNo: body.legalPersonNo, legalPersonNo: body.identityNumber,
customer: { customer: {
customerType: "CORP", customerType: "CORP",
}, },
}), },
],
}, },
}); });