From 2da138939ceffc4b2275991d99db8edbd630b240 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 21 Feb 2025 10:06:00 +0700 Subject: [PATCH] refactor: change verify input as frontend cannot detect type --- src/controllers/09-verification-controller.ts | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/controllers/09-verification-controller.ts b/src/controllers/09-verification-controller.ts index b607ee8..aa1bb4f 100644 --- a/src/controllers/09-verification-controller.ts +++ b/src/controllers/09-verification-controller.ts @@ -7,13 +7,15 @@ import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; type SendEmail = { + identityNumber: string; email: string; -} & ({ legalPersonNo: string } | { citizenId: string }); +}; type VerificationPayload = { + identityNumber: string; email: string; otp: string; -} & ({ legalPersonNo: string } | { citizenId: string }); +}; let emailTransport: ReturnType<(typeof nodemailer)["createTransport"]>; @@ -61,19 +63,20 @@ export class verificationController extends Controller { const dataCustomerBranch = await prisma.customerBranch.findFirst({ where: { email: body.email, - ...("citizenId" in body - ? { - citizenId: body.citizenId, - customer: { - customerType: "PERS", - }, - } - : { - legalPersonNo: body.legalPersonNo, - customer: { - customerType: "CORP", - }, - }), + OR: [ + { + citizenId: body.identityNumber, + customer: { + customerType: "PERS", + }, + }, + { + legalPersonNo: body.identityNumber, + customer: { + customerType: "CORP", + }, + }, + ], }, }); @@ -105,19 +108,20 @@ export class verificationController extends Controller { const customerBranch = await prisma.customerBranch.findFirst({ where: { email: body.email, - ...("citizenId" in body - ? { - citizenId: body.citizenId, - customer: { - customerType: "PERS", - }, - } - : { - legalPersonNo: body.legalPersonNo, - customer: { - customerType: "CORP", - }, - }), + OR: [ + { + citizenId: body.identityNumber, + customer: { + customerType: "PERS", + }, + }, + { + legalPersonNo: body.identityNumber, + customer: { + customerType: "CORP", + }, + }, + ], }, });