From 126eced955eacc9858172deb54134d72d0ff93a4 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Feb 2024 16:48:11 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B9=80=E0=B8=87=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99?= =?UTF-8?q?=E0=B9=84=E0=B8=82=20cron-job=20=E0=B9=81=E0=B8=A5=E0=B8=B0=20?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=20validate=20Prof?= =?UTF-8?q?ileController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 10 +++++++ src/controllers/ProfileController.ts | 34 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index f9683365..b52b2768 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1576,6 +1576,16 @@ export class OrganizationController extends Controller { orgRevisionDraft.orgRevisionIsCurrent = true; orgRevisionDraft.orgRevisionIsDraft = false; await this.orgRevisionRepository.save(orgRevisionDraft); + + const posMaster = await this.posMasterRepository.find({ + where: { orgRevisionId: orgRevisionDraft.id }, + }); + posMaster.forEach(async (item) => { + item.current_holderId = item.next_holderId; + item.next_holderId = null; + await this.posMasterRepository.save(item); + }); + return new HttpSuccess(); } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index d296a653..f91b3d7d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -51,6 +51,9 @@ export class ProfileController extends Controller { requestBody: CreateProfile, @Request() request: { user: Record }, ) { + if (requestBody.posLevelId == "") { + requestBody.posLevelId = null; + } if (requestBody.posLevelId) { const checkPosLevel = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, @@ -63,6 +66,9 @@ export class ProfileController extends Controller { } } + if (requestBody.posTypeId == "") { + requestBody.posTypeId = null; + } if (requestBody.posTypeId) { const checkPosType = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, @@ -75,6 +81,17 @@ export class ProfileController extends Controller { } } + const checkCitizenId = await this.profileRepository.findOne({ + where: { citizenId: requestBody.citizenId }, + }); + + if (checkCitizenId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "มีรหัสประจำตัวประชาชนนี้แล้วในระบบ (citizenId)", + ); + } + try { const profile = Object.assign(new Profile(), requestBody); profile.createdUserId = request.user.sub; @@ -107,6 +124,9 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); } + if (requestBody.posLevelId == "") { + requestBody.posLevelId = null; + } if (requestBody.posLevelId) { const checkPosLevel = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, @@ -119,6 +139,9 @@ export class ProfileController extends Controller { } } + if (requestBody.posTypeId == "") { + requestBody.posTypeId = null; + } if (requestBody.posTypeId) { const checkPosType = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, @@ -131,6 +154,17 @@ export class ProfileController extends Controller { } } + const checkCitizenId = await this.profileRepository.findOne({ + where: { citizenId: requestBody.citizenId }, + }); + + if (checkCitizenId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "มีรหัสประจำตัวประชาชนนี้แล้วในระบบ (citizenId)", + ); + } + try { profile.lastUpdateUserId = request.user.sub; profile.lastUpdateFullName = request.user.name; From 961677cb19ff5fb624b0be14444164880e45d9b7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Feb 2024 17:06:21 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E0=B9=80=E0=B8=9C=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=95=E0=B9=89=E0=B8=AD=E0=B8=87=E0=B9=80=E0=B8=8A?= =?UTF-8?q?=E0=B9=87=E0=B8=84=E0=B8=84=E0=B9=88=E0=B8=B2=E0=B8=A7=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=20next=5FholderId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index b52b2768..b4761871 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1581,9 +1581,11 @@ export class OrganizationController extends Controller { where: { orgRevisionId: orgRevisionDraft.id }, }); posMaster.forEach(async (item) => { - item.current_holderId = item.next_holderId; - item.next_holderId = null; - await this.posMasterRepository.save(item); + // if(item.next_holderId != null){ + item.current_holderId = item.next_holderId; + item.next_holderId = null; + await this.posMasterRepository.save(item); + // } }); return new HttpSuccess();