From 614fe24e12459672679e6738c57977871bfc06e6 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 21 Feb 2024 13:53:02 +0700 Subject: [PATCH] no message --- src/controllers/ProfileController.ts | 73 +++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e62eaa47..da744888 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -51,6 +51,12 @@ export class ProfileController extends Controller { requestBody: CreateProfile, @Request() request: { user: Record }, ) { + const _profile = await this.profileRepository.findOne({ + where: { citizenId: requestBody.citizenId }, + }); + if (_profile) { + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เลขบัตรนี้มีอยู่ในระบบแล้ว"); + } if (requestBody.posLevelId == "") { requestBody.posLevelId = null; } @@ -124,6 +130,13 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); } + const _profile = await this.profileRepository.findOne({ + where: { id: Not(id), citizenId: requestBody.citizenId }, + }); + if (_profile) { + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เลขบัตรนี้มีอยู่ในระบบแล้ว"); + } + if (requestBody.posLevelId == "") { requestBody.posLevelId = null; } @@ -155,9 +168,9 @@ export class ProfileController extends Controller { } const checkCitizenId = await this.profileRepository.findOne({ - where: { + where: { id: Not(id), - citizenId: requestBody.citizenId , + citizenId: requestBody.citizenId, }, }); @@ -619,17 +632,37 @@ export class ProfileController extends Controller { .orderBy("posMaster.posMasterOrder", "ASC") .getOne(); } - fullName_ = (findProfile?.prefix ?? "") + (findProfile?.firstName ?? "") + " " + (findProfile?.lastName ?? ""); + fullName_ = + (findProfile?.prefix ?? "") + + (findProfile?.firstName ?? "") + + " " + + (findProfile?.lastName ?? ""); position_ = findProfile?.position ?? ""; - commanderFullname_ = (findCmd?.current_holder?.prefix ?? "") + (findCmd?.current_holder?.firstName ?? "") + " " + (findCmd?.current_holder?.lastName ?? ""); + commanderFullname_ = + (findCmd?.current_holder?.prefix ?? "") + + (findCmd?.current_holder?.firstName ?? "") + + " " + + (findCmd?.current_holder?.lastName ?? ""); commanderPosition_ = findCmd?.current_holder?.position ?? ""; - commanderAboveFullname_ = (findOSAB?.current_holder?.prefix ?? "") + (findOSAB?.current_holder?.firstName ?? "") + " " + (findOSAB?.current_holder?.lastName ?? ""); + commanderAboveFullname_ = + (findOSAB?.current_holder?.prefix ?? "") + + (findOSAB?.current_holder?.firstName ?? "") + + " " + + (findOSAB?.current_holder?.lastName ?? ""); commanderAbovePosition_ = findOSAB?.current_holder?.position ?? ""; if (findCmd?.current_holderId == findProfile?.id) { - commanderFullname_ = (findOSAB?.current_holder?.prefix ?? "") + (findOSAB?.current_holder?.firstName ?? "") + " " + (findOSAB?.current_holder?.lastName ?? ""); + commanderFullname_ = + (findOSAB?.current_holder?.prefix ?? "") + + (findOSAB?.current_holder?.firstName ?? "") + + " " + + (findOSAB?.current_holder?.lastName ?? ""); commanderPosition_ = findOSAB?.current_holder?.position ?? ""; - commanderAboveFullname_ = (findTSAB?.current_holder?.prefix ?? "") + (findTSAB?.current_holder?.firstName ?? "") + " " + (findTSAB?.current_holder?.lastName ?? ""); + commanderAboveFullname_ = + (findTSAB?.current_holder?.prefix ?? "") + + (findTSAB?.current_holder?.firstName ?? "") + + " " + + (findTSAB?.current_holder?.lastName ?? ""); commanderAbovePosition_ = findTSAB?.current_holder?.position ?? ""; const formattedDataTSAB = { @@ -653,4 +686,30 @@ export class ProfileController extends Controller { }; return new HttpSuccess(formattedData); } + + /** + * API เช็คเลขบัตร + * + * @summary เช็คเลขบัตร (ADMIN) + * + * @param {string} id Id ทะเบียนประวัติ + */ + @Put("citizenId/{id}") + async checkCitizenIdProfile( + @Path() id: string, + @Body() + requestBody: { citizenId: string }, + ) { + const profile = await this.profileRepository.findOne({ + where: { id: Not(id), citizenId: requestBody.citizenId }, + }); + if (profile) { + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เลขบัตรนี้มีอยู่ในระบบแล้ว"); + } + try { + return new HttpSuccess(); + } catch (error) { + return error; + } + } }