From d01ca5f06171f9bfc45bd10b6db7e83c7edca634 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 21 Nov 2024 17:32:31 +0700 Subject: [PATCH] fix --- .../OrganizationUnauthorizeController.ts | 30 +++++++++++++++++++ src/controllers/ProfileController.ts | 29 ------------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 4fdfbf92..caf55741 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -11,6 +11,7 @@ import { calculateRetireDate } from "../interfaces/utils"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import HttpStatus from "../interfaces/http-status"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @@ -1123,4 +1124,33 @@ export class OrganizationUnauthorizeController extends Controller { return new HttpSuccess(mapProfile); } + + /** + * API ยืนยัน Email + * + * @summary ยืนยัน Email + * + */ + @Post("verify-email") + async genLinkVerifyEmail(@Body() body: { token: string }) { + const jwt = require("jsonwebtoken"); + const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey"; + const decodedToken = jwt.verify(body.token, secretKey); + // console.log("[email]",decodedToken); + // console.log("[1]",decodedToken.email_id); + + const profile = await this.profileRepo.findOne({ + where: { + id: decodedToken.profileId, + email: decodedToken.email_id, + }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } + + Object.assign(profile, body); + profile.statusEmail = "VERIFIED"; + await this.profileRepo.save(profile); + } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c53be4fe..0752fb01 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1902,35 +1902,6 @@ export class ProfileController extends Controller { return new HttpSuccess(); } - /** - * API ยืนยัน Email - * - * @summary ยืนยัน Email - * - */ - @Post("verify-email") - async genLinkVerifyEmail(@Body() body: { token: string }) { - const jwt = require("jsonwebtoken"); - const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey"; - const decodedToken = jwt.verify(body.token, secretKey); - // console.log("[email]",decodedToken); - // console.log("[1]",decodedToken.email_id); - - const profile = await this.profileRepo.findOne({ - where: { - id: decodedToken.profileId, - email: decodedToken.email_id, - }, - }); - if (!profile) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); - } - - Object.assign(profile, body); - profile.statusEmail = "VERIFIED"; - await this.profileRepo.save(profile); - } - /** * API ออกคำสั่ง คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป *