This commit is contained in:
AdisakKanthawilang 2024-11-01 13:55:37 +07:00
parent e0f78a89e9
commit c082ae8891

View file

@ -1700,7 +1700,10 @@ export class PositionController extends Controller {
...checkChildConditions, ...checkChildConditions,
...typeCondition, ...typeCondition,
...revisionCondition, ...revisionCondition,
...(masterId.length > 0 ? { id: In(masterId) } : {}), ...(body.keyword &&
(masterId.length > 0
? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })),
}, },
]; ];
@ -1765,9 +1768,7 @@ export class PositionController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.andWhere( .orWhere(
new Brackets((qb) => {
qb.orWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
@ -1811,22 +1812,6 @@ export class PositionController extends Controller {
.andWhere(revisionCondition); .andWhere(revisionCondition);
}), }),
) )
.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);
}),
);
}),
)
.orderBy("posMaster.posMasterOrder", "ASC") .orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize) .skip((body.page - 1) * body.pageSize)
.take(body.pageSize) .take(body.pageSize)
@ -1839,11 +1824,11 @@ export class PositionController extends Controller {
if (body.keyword != null && body.keyword != ""){ if (body.keyword != null && body.keyword != ""){
const position = await this.positionRepository.find({ const position = await this.positionRepository.find({
relations: ["posType", "posLevel", "posExecutive"], relations: ["posType", "posLevel", "posExecutive"],
where: { posMasterId: In(posMaster.map((x) => x.id)) }, where: { posMasterId: In(posMaster.map(x => x.id))},
order: { createdAt: "ASC" }, order: { createdAt: "ASC" }
}); });
for(let data of position){ for(let data of position){
x = data.posMasterId; x = data.posMasterId
if(y != x){ if(y != x){
if( if(
data.positionName.includes(body.keyword) || data.positionName.includes(body.keyword) ||
@ -1858,9 +1843,10 @@ export class PositionController extends Controller {
} }
if(_position.length > 0){ if(_position.length > 0){
posMaster = posMaster.filter((x) => _position.some((y) => y.posMasterId === x.id)); posMaster = posMaster.filter((x) => _position.some(y => y.posMasterId === x.id));
} }
const formattedData = await Promise.all( const formattedData = await Promise.all(
posMaster.map(async (posMaster) => { posMaster.map(async (posMaster) => {
const positions = await this.positionRepository.find({ const positions = await this.positionRepository.find({