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 รายการทะเบียนประวัติ *