diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 3b4d0f0c..4a1566f6 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -1154,7 +1154,7 @@ export class EmployeePositionController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `posMaster.orgChild1Id IN (:...child1)` - : `posMaster.orgChild1Id is null` + : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -1381,24 +1381,22 @@ export class EmployeePositionController extends Controller { }; }), ); - - if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า - const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป + + if (_data.privilege === "NORMAL" || _data.privilege === "CHILD") { + //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า + const nextChildMap: any = { + //เอาไวเช็ค CHILD ถัดไป 0: _data.child1, 1: _data.child2, 2: _data.child3, 3: _data.child4, }; const childValue = nextChildMap[body.type]; - if(_data.privilege === 'NORMAL'){ - if (Array.isArray(childValue) && childValue.some(item => item != null)) { + if (_data.privilege === "NORMAL") { + if (Array.isArray(childValue) && childValue.some((item) => item != null)) { return new HttpSuccess({ data: [], total: 0 }); } - }else if(_data.privilege === 'PARENT'){ - if (body.type == 0){ - return new HttpSuccess({ data: [], total: 0 }); - } - } else if (_data.privilege === 'CHILD') { + } else if (_data.privilege === "CHILD") { const higherChildChecks = [ { type: [0], child: _data.child1, next: _data.child2 }, { type: [0, 1], child: _data.child2, next: _data.child3 }, diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 50c58a4b..7ef5ff48 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -902,7 +902,7 @@ export class EmployeeTempPositionController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `posMaster.orgChild1Id IN (:...child1)` - : `posMaster.orgChild1Id is null` + : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -1129,23 +1129,21 @@ export class EmployeeTempPositionController extends Controller { }; }), ); - if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า - const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป + if (_data.privilege === "NORMAL" || _data.privilege === "CHILD") { + //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า + const nextChildMap: any = { + //เอาไวเช็ค CHILD ถัดไป 0: _data.child1, 1: _data.child2, 2: _data.child3, 3: _data.child4, }; const childValue = nextChildMap[body.type]; - if(_data.privilege === 'NORMAL'){ - if (Array.isArray(childValue) && childValue.some(item => item != null)) { + if (_data.privilege === "NORMAL") { + if (Array.isArray(childValue) && childValue.some((item) => item != null)) { return new HttpSuccess({ data: [], total: 0 }); } - }else if(_data.privilege === 'PARENT'){ - if (body.type == 0){ - return new HttpSuccess({ data: [], total: 0 }); - } - } else if (_data.privilege === 'CHILD') { + } else if (_data.privilege === "CHILD") { const higherChildChecks = [ { type: [0], child: _data.child1, next: _data.child2 }, { type: [0, 1], child: _data.child2, next: _data.child3 }, diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 34be7a8e..84144021 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -963,40 +963,40 @@ export class PositionController extends Controller { } let orgRoot: any = null; let SName: any = null; - let revisionId:any = null; + let revisionId: any = null; if (requestBody.orgRootId != null) orgRoot = await this.orgRootRepository.findOne({ where: { id: requestBody.orgRootId }, }); - revisionId = orgRoot?.orgRevisionId; + revisionId = orgRoot?.orgRevisionId; if (!orgRoot) { let orgChild1: any = null; if (requestBody.orgChild1Id != null) orgChild1 = await this.child1Repository.findOne({ where: { id: requestBody.orgChild1Id }, }); - revisionId = orgChild1?.orgRevisionId; + revisionId = orgChild1?.orgRevisionId; if (!orgChild1) { let orgChild2: any = null; if (requestBody.orgChild2Id != null) orgChild2 = await this.child2Repository.findOne({ where: { id: requestBody.orgChild2Id }, }); - revisionId = orgChild2?.orgRevisionId; + revisionId = orgChild2?.orgRevisionId; if (!orgChild2) { let orgChild3: any = null; if (requestBody.orgChild3Id != null) orgChild3 = await this.child3Repository.findOne({ where: { id: requestBody.orgChild3Id }, }); - revisionId = orgChild3?.orgRevisionId; + revisionId = orgChild3?.orgRevisionId; if (!orgChild3) { let orgChild4: any = null; if (requestBody.orgChild4Id != null) orgChild4 = await this.child4Repository.findOne({ where: { id: requestBody.orgChild4Id }, }); - revisionId = orgChild4?.orgRevisionId; + revisionId = orgChild4?.orgRevisionId; if (!orgChild4) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); } else { @@ -1169,9 +1169,9 @@ export class PositionController extends Controller { ); } const before = null; - let chkRevision:any = null; - if(revisionId){ - chkRevision = await this.orgRevisionRepository.findOne({ + let chkRevision: any = null; + if (revisionId) { + chkRevision = await this.orgRevisionRepository.findOne({ where: { id: revisionId }, }); } @@ -2265,7 +2265,7 @@ export class PositionController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `posMaster.orgChild1Id IN (:...child1)` - : `posMaster.orgChild1Id is null` + : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -2301,48 +2301,52 @@ export class PositionController extends Controller { child4: _data.child4, }, ) - .orWhere( + .andWhere( new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? body.isAll == false - ? searchShortName - : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` - : "1=1", + qb.orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? body.isAll == false + ? searchShortName + : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` + : "1=1", + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ); }), ) .orderBy("orgRoot.orgRootOrder", "ASC") @@ -2520,24 +2524,22 @@ export class PositionController extends Controller { }; }), ); - - if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า - const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป + + if (_data.privilege === "NORMAL" || _data.privilege === "CHILD") { + //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า + const nextChildMap: any = { + //เอาไวเช็ค CHILD ถัดไป 0: _data.child1, 1: _data.child2, 2: _data.child3, 3: _data.child4, }; const childValue = nextChildMap[body.type]; - if(_data.privilege === 'NORMAL'){ - if (Array.isArray(childValue) && childValue.some(item => item != null)) { + if (_data.privilege === "NORMAL") { + if (Array.isArray(childValue) && childValue.some((item) => item != null)) { return new HttpSuccess({ data: [], total: 0 }); } - }else if(_data.privilege === 'PARENT'){ - if (body.type == 0){ - return new HttpSuccess({ data: [], total: 0 }); - } - } else if (_data.privilege === 'CHILD') { + } else if (_data.privilege === "CHILD") { const higherChildChecks = [ { type: [0], child: _data.child1, next: _data.child2 }, { type: [0, 1], child: _data.child2, next: _data.child3 }, @@ -3751,7 +3753,6 @@ export class PositionController extends Controller { }); }); - // //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile // const chkRevision = await this.orgRevisionRepository.findOne({ // where: { id: dataMaster.orgRevisionId }, @@ -5290,7 +5291,7 @@ export class PositionController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `posMaster.orgChild1Id IN (:...child1)` - : `posMaster.orgChild1Id is null` + : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index e843b218..0bbeff46 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1028,12 +1028,15 @@ export class ProfileEmployeeTempController extends Controller { if (!result) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - - try{ + + try { await this.informationHistoryRepository.delete({ profileEmployeeId: id }); await this.profileRepo.remove(result); } catch { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น"); + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น", + ); } return new HttpSuccess(); } @@ -1106,7 +1109,7 @@ export class ProfileEmployeeTempController extends Controller { _dataOrg.child1 != undefined && _dataOrg.child1 != null ? _dataOrg.child1[0] != null ? `current_holderTemps.orgChild1Id IN (:...child1)` - : `current_holderTemps.orgChild1Id is null` + : `current_holderTemps.orgChild1Id is ${_dataOrg.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _dataOrg.child1, @@ -1561,7 +1564,7 @@ export class ProfileEmployeeTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holderTemps.orgChild1Id IN (:...child1)` - : `current_holderTemps.orgChild1Id is null` + : `current_holderTemps.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -2270,7 +2273,7 @@ export class ProfileEmployeeTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holderTemps.orgChild1Id IN (:...child1)` - : `current_holderTemps.orgChild1Id is null` + : `current_holderTemps.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1 }, )