diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 8ae8daf3..d017538d 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1234,7 +1234,7 @@ export class PositionController extends Controller { : { posMasterNo: Like(`%${body.keyword}%`) })), }, ]; - + let [posMaster, total] = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") @@ -1296,51 +1296,55 @@ export class PositionController extends Controller { child4: _data.child4, }, ) - // .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); - // }), - // ) - // .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("posMaster.posMasterOrder", "ASC") + .andWhere( + new Brackets((qb) => { + 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); + }), + ) + .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("posMaster.posMasterOrder", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount();