From f612ecf0e2870dbc2848f06ef4f7e3d9ae171be1 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 29 Apr 2024 16:01:47 +0700 Subject: [PATCH] no message --- src/controllers/PositionController.ts | 254 +++++++++++++------------- 1 file changed, 132 insertions(+), 122 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index bfe19f29..04cbe46e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -823,81 +823,81 @@ export class PositionController extends Controller { } // if (posMaster.orgChild4Id != null) { - const chk_SName4 = await this.posMasterRepository.findOne({ - where: { - orgChild4: { orgChild4ShortName: SName }, - posMasterNo: requestBody.posMasterNo, - id: Not(posMaster.id), - }, - }); - if (chk_SName4 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", - ); - } + const chk_SName4 = await this.posMasterRepository.findOne({ + where: { + orgChild4: { orgChild4ShortName: SName }, + posMasterNo: requestBody.posMasterNo, + id: Not(posMaster.id), + }, + }); + if (chk_SName4 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", + ); + } // } else if (posMaster.orgChild3Id != null) { - const chk_SName3 = await this.posMasterRepository.findOne({ - where: { - orgChild3: { orgChild3ShortName: SName }, - posMasterNo: requestBody.posMasterNo, - orgChild4Id: IsNull(), - id: Not(posMaster.id), - }, - }); - if (chk_SName3 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", - ); - } + const chk_SName3 = await this.posMasterRepository.findOne({ + where: { + orgChild3: { orgChild3ShortName: SName }, + posMasterNo: requestBody.posMasterNo, + orgChild4Id: IsNull(), + id: Not(posMaster.id), + }, + }); + if (chk_SName3 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", + ); + } // } else if (posMaster.orgChild2Id != null) { - const chk_SName2 = await this.posMasterRepository.findOne({ - where: { - orgChild2: { orgChild2ShortName: SName }, - posMasterNo: requestBody.posMasterNo, - orgChild3Id: IsNull(), - id: Not(posMaster.id), - }, - }); - if (chk_SName2 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", - ); - } + const chk_SName2 = await this.posMasterRepository.findOne({ + where: { + orgChild2: { orgChild2ShortName: SName }, + posMasterNo: requestBody.posMasterNo, + orgChild3Id: IsNull(), + id: Not(posMaster.id), + }, + }); + if (chk_SName2 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", + ); + } // } else if (posMaster.orgChild1Id != null) { - const chk_SName1 = await this.posMasterRepository.findOne({ - where: { - orgChild1: { orgChild1ShortName: SName }, - posMasterNo: requestBody.posMasterNo, - orgChild2Id: IsNull(), - id: Not(posMaster.id), - }, - }); - if (chk_SName1 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", - ); - } + const chk_SName1 = await this.posMasterRepository.findOne({ + where: { + orgChild1: { orgChild1ShortName: SName }, + posMasterNo: requestBody.posMasterNo, + orgChild2Id: IsNull(), + id: Not(posMaster.id), + }, + }); + if (chk_SName1 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", + ); + } // } else if (posMaster.orgRootId != null) { - const chk_SName0 = await this.posMasterRepository.findOne({ - where: { - orgRoot: { orgRootShortName: SName }, - posMasterNo: requestBody.posMasterNo, - orgChild1Id: IsNull(), - id: Not(posMaster.id), - }, - }); - if (chk_SName0 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", - ); - } + const chk_SName0 = await this.posMasterRepository.findOne({ + where: { + orgRoot: { orgRootShortName: SName }, + posMasterNo: requestBody.posMasterNo, + orgChild1Id: IsNull(), + id: Not(posMaster.id), + }, + }); + if (chk_SName0 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้", + ); + } // } - + posMaster.createdUserId = request.user.sub; posMaster.createdFullName = request.user.name; posMaster.lastUpdateUserId = request.user.sub; @@ -1198,8 +1198,8 @@ export class PositionController extends Controller { posMasterId: posMaster.id, }, relations: ["posLevel", "posType", "posExecutive"], - order:{ - createdAt: "ASC" + order: { + createdAt: "ASC", }, }); @@ -1589,7 +1589,7 @@ export class PositionController extends Controller { ]; // let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0); - let _shortName : string + let _shortName: string; let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0); await Promise.all( posMasters.map(async (posMaster: any) => { @@ -1600,7 +1600,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - _shortName = org.orgRootShortName + _shortName = org.orgRootShortName; const _posMaster = await this.posMasterRepository.findOne({ where: { orgRootId: org.id, @@ -1634,7 +1634,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - _shortName = org.orgChild1ShortName + _shortName = org.orgChild1ShortName; const _posMaster = await this.posMasterRepository.findOne({ where: { orgChild1Id: org.id, @@ -1667,7 +1667,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - _shortName = org.orgChild2ShortName + _shortName = org.orgChild2ShortName; const _posMaster = await this.posMasterRepository.findOne({ where: { orgChild2Id: org.id, @@ -1699,7 +1699,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - _shortName = org.orgChild3ShortName + _shortName = org.orgChild3ShortName; const _posMaster = await this.posMasterRepository.findOne({ where: { orgChild3Id: org.id, @@ -1726,7 +1726,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - _shortName = org.orgChild4ShortName + _shortName = org.orgChild4ShortName; const _posMaster = await this.posMasterRepository.findOne({ where: { orgChild4Id: org.id, @@ -1752,28 +1752,28 @@ export class PositionController extends Controller { //CheckAll const orgRevision = await this.orgRevisionRepository.findOne({ where: { - orgRevisionIsDraft: true, + orgRevisionIsDraft: true, orgRevisionIsCurrent: false, - } - }) + }, + }); const _orgRoot = await this.orgRootRepository.find({ where: { orgRevisionId: orgRevision?.id, orgRootShortName: _shortName, id: Not(requestBody.id), - } - }) - if(_orgRoot.length > 0){ - for(const r of _orgRoot){ + }, + }); + if (_orgRoot.length > 0) { + for (const r of _orgRoot) { const _posMasterRoot = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, orgRootId: r.id, orgChild1Id: IsNull() || "", - posMasterNo: posMaster.posMasterNo - } - }) - if(_posMasterRoot != null){ + posMasterNo: posMaster.posMasterNo, + }, + }); + if (_posMasterRoot != null) { throw new HttpError( HttpStatusCode.NOT_FOUND, `เลขที่ตำแหน่ง ${r.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`, @@ -1787,19 +1787,19 @@ export class PositionController extends Controller { orgRevisionId: orgRevision?.id, orgChild1ShortName: _shortName, id: Not(requestBody.id), - } - }) - if(_orgChild1.length > 0){ - for(const c1 of _orgChild1){ + }, + }); + if (_orgChild1.length > 0) { + for (const c1 of _orgChild1) { const _posMasterChild1 = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, orgChild1Id: c1.id, orgChild2Id: IsNull() || "", - posMasterNo: posMaster.posMasterNo - } - }) - if(_posMasterChild1 != null){ + posMasterNo: posMaster.posMasterNo, + }, + }); + if (_posMasterChild1 != null) { throw new HttpError( HttpStatusCode.NOT_FOUND, `เลขที่ตำแหน่ง ${c1.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`, @@ -1813,19 +1813,19 @@ export class PositionController extends Controller { orgRevisionId: orgRevision?.id, orgChild2ShortName: _shortName, id: Not(requestBody.id), - } - }) - if(_orgChild2.length > 0){ - for(const c2 of _orgChild2){ + }, + }); + if (_orgChild2.length > 0) { + for (const c2 of _orgChild2) { const _posMasterChild2 = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, orgChild2Id: c2.id, orgChild3Id: IsNull() || "", - posMasterNo: posMaster.posMasterNo - } - }) - if(_posMasterChild2 != null){ + posMasterNo: posMaster.posMasterNo, + }, + }); + if (_posMasterChild2 != null) { throw new HttpError( HttpStatusCode.NOT_FOUND, `เลขที่ตำแหน่ง ${c2.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`, @@ -1839,19 +1839,19 @@ export class PositionController extends Controller { orgRevisionId: orgRevision?.id, orgChild3ShortName: _shortName, id: Not(requestBody.id), - } - }) - if(_orgChild3.length > 0){ - for(const c3 of _orgChild3){ + }, + }); + if (_orgChild3.length > 0) { + for (const c3 of _orgChild3) { const _posMasterChild3 = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, orgChild3Id: c3.id, orgChild4Id: IsNull() || "", - posMasterNo: posMaster.posMasterNo - } - }) - if(_posMasterChild3 != null){ + posMasterNo: posMaster.posMasterNo, + }, + }); + if (_posMasterChild3 != null) { throw new HttpError( HttpStatusCode.NOT_FOUND, `เลขที่ตำแหน่ง ${c3.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`, @@ -1865,18 +1865,18 @@ export class PositionController extends Controller { orgRevisionId: orgRevision?.id, orgChild4ShortName: _shortName, id: Not(requestBody.id), - } - }) - if(_orgChild4.length > 0){ - for(const c4 of _orgChild4){ + }, + }); + if (_orgChild4.length > 0) { + for (const c4 of _orgChild4) { const _posMasterChild4 = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, orgChild4Id: c4.id, - posMasterNo: posMaster.posMasterNo - } - }) - if(_posMasterChild4 != null){ + posMasterNo: posMaster.posMasterNo, + }, + }); + if (_posMasterChild4 != null) { throw new HttpError( HttpStatusCode.NOT_FOUND, `เลขที่ตำแหน่ง ${c4.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`, @@ -2462,7 +2462,17 @@ export class PositionController extends Controller { * */ @Post("placement/search") - async searchPlacement(@Body() body: { node: number; nodeId: string; position: string }) { + async searchPlacement( + @Body() + body: { + node: number; + nodeId: string; + position: string; + typeCommand: string; + posType: string; + posLevel: string; + }, + ) { let typeCondition: any = {}; if (body.node === 0) {