From 6924017849973306372a3c26c79c12e371252db1 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:28:39 +0700 Subject: [PATCH] fix: update without pos field always result in null --- src/controllers/ProfileController.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6733096d..98f15f81 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -58,8 +58,8 @@ export class ProfileController extends Controller { ); } - if (!body.posLevelId) body.posLevelId = null; - if (!body.posTypeId) body.posTypeId = null; + if (body.posLevelId === "") body.posLevelId = null; + if (body.posTypeId === "") body.posTypeId = null; if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); @@ -102,8 +102,8 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.CONFLICT, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); } - if (!body.posLevelId) body.posLevelId = null; - if (!body.posTypeId) body.posTypeId = null; + if (body.posLevelId === "") body.posLevelId = null; + if (body.posTypeId === "") body.posTypeId = null; if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); @@ -120,6 +120,7 @@ export class ProfileController extends Controller { await this.profileHistoryRepo.save( Object.assign(new ProfileHistory(), { ...record, + profileId: id, id: undefined, }), ); @@ -176,6 +177,24 @@ export class ProfileController extends Controller { return new HttpSuccess(profile); } + @Get("history/{id}") + async getProfileHistory(@Path() id: string) { + const profile = await this.profileHistoryRepo.find({ + relations: { + posLevel: true, + posType: true, + gender: true, + relationship: true, + bloodGroup: true, + }, + where: { profileId: id }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + return new HttpSuccess(profile); + } + /** * API รายการทะเบียนประวัติ *