Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-05-23 10:07:50 +07:00
commit 732467965e

View file

@ -2961,179 +2961,184 @@ export class PositionController extends Controller {
return new HttpSuccess({ data: formattedData, total }); return new HttpSuccess({ data: formattedData, total });
} }
/** /**
* API * API
* *
* @summary * @summary
* *
*/ */
@Post("profile/search") @Post("profile/search")
async searchProfile( async searchProfile(
@Body() @Body()
body: { body: {
isAll: boolean; isAll: boolean;
node: number; node: number;
nodeId: string; nodeId: string;
}, },
) { ) {
let typeCondition: any = {}; let typeCondition: any = {};
if (body.isAll == false) { if (body.isAll == false) {
if (body.node === 0) { if (body.node === 0) {
typeCondition = { typeCondition = {
orgRootId: body.nodeId, orgRootId: body.nodeId,
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
}; };
} else if (body.node === 1) { } else if (body.node === 1) {
typeCondition = { typeCondition = {
orgChild1Id: body.nodeId, orgChild1Id: body.nodeId,
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
}; };
} else if (body.node === 2) { } else if (body.node === 2) {
typeCondition = { typeCondition = {
orgChild2Id: body.nodeId, orgChild2Id: body.nodeId,
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
}; };
} else if (body.node === 3) { } else if (body.node === 3) {
typeCondition = { typeCondition = {
orgChild3Id: body.nodeId, orgChild3Id: body.nodeId,
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
}; };
} else if (body.node === 4) { } else if (body.node === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.nodeId, orgChild4Id: body.nodeId,
}; };
} }
} else { } else {
if (body.node === 0) { if (body.node === 0) {
typeCondition = { typeCondition = {
orgRootId: body.nodeId, orgRootId: body.nodeId,
}; };
} else if (body.node === 1) { } else if (body.node === 1) {
typeCondition = { typeCondition = {
orgChild1Id: body.nodeId, orgChild1Id: body.nodeId,
}; };
} else if (body.node === 2) { } else if (body.node === 2) {
typeCondition = { typeCondition = {
orgChild2Id: body.nodeId, orgChild2Id: body.nodeId,
}; };
} else if (body.node === 3) { } else if (body.node === 3) {
typeCondition = { typeCondition = {
orgChild3Id: body.nodeId, orgChild3Id: body.nodeId,
}; };
} else if (body.node === 4) { } else if (body.node === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.nodeId, orgChild4Id: body.nodeId,
}; };
} }
} }
const [posMaster, total] = await AppDataSource.getRepository(PosMaster) const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster") .createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2") .leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3") .leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4") .leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.current_holder", "current_holder") .leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.next_holder", "next_holder") .leftJoinAndSelect("posMaster.next_holder", "next_holder")
.leftJoinAndSelect("posMaster.positions", "positions") .leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posType", "posType") .leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel") .leftJoinAndSelect("positions.posLevel", "posLevel")
.where("posMaster.current_holderId IS NOT NULL") .where("posMaster.current_holderId IS NOT NULL")
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.orWhere(typeCondition); qb.orWhere(typeCondition);
}), }),
) )
.orderBy("posMaster.posMasterOrder", "ASC") .orderBy("posMaster.posMasterOrder", "ASC")
.getManyAndCount(); .getManyAndCount();
const formattedData = await Promise.all(
posMaster.map(async (posMaster) => {
let shortName = "";
if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id == null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null
) {
body.node = 0;
shortName = posMaster.orgRoot.orgRootShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null
) {
body.node = 1;
shortName = posMaster.orgChild1.orgChild1ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id == null
) {
body.node = 2;
shortName = posMaster.orgChild2.orgChild2ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id !== null
) {
body.node = 3;
shortName = posMaster.orgChild3.orgChild3ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id !== null
) {
body.node = 4;
shortName = posMaster.orgChild4.orgChild4ShortName;
}
const formattedData = await Promise.all( let node: any = null;
posMaster.map(async (posMaster) => { let nodeId: any = null;
let shortName = ""; if (posMaster.orgChild4Id != null) {
if ( node = 4;
posMaster.orgRootId !== null && nodeId = posMaster.orgChild4Id;
posMaster.orgChild1Id == null && } else if (posMaster.orgChild3Id != null) {
posMaster.orgChild2Id == null && node = 3;
posMaster.orgChild3Id == null nodeId = posMaster.orgChild3Id;
) { } else if (posMaster.orgChild2Id != null) {
body.node = 0; node = 2;
shortName = posMaster.orgRoot.orgRootShortName; nodeId = posMaster.orgChild2Id;
} else if ( } else if (posMaster.orgChild1Id != null) {
posMaster.orgRootId !== null && node = 1;
posMaster.orgChild1Id !== null && nodeId = posMaster.orgChild1Id;
posMaster.orgChild2Id == null && } else if (posMaster.orgRootId != null) {
posMaster.orgChild3Id == null node = 0;
) { nodeId = posMaster.orgRootId;
body.node = 1; }
shortName = posMaster.orgChild1.orgChild1ShortName; const fullname =
} else if ( posMaster.current_holder.prefix +
posMaster.orgRootId !== null && " " +
posMaster.orgChild1Id !== null && posMaster.current_holder.firstName +
posMaster.orgChild2Id !== null && " " +
posMaster.orgChild3Id == null posMaster.current_holder.lastName;
) { return {
body.node = 2; id: posMaster.id,
shortName = posMaster.orgChild2.orgChild2ShortName; node: node,
} else if ( nodeId: nodeId,
posMaster.orgRootId !== null && orgRootId: posMaster.orgRootId,
posMaster.orgChild1Id !== null && orgChild1Id: posMaster.orgChild1Id,
posMaster.orgChild2Id !== null && orgChild2Id: posMaster.orgChild2Id,
posMaster.orgChild3Id !== null orgChild3Id: posMaster.orgChild3Id,
) { orgChild4Id: posMaster.orgChild4Id,
body.node = 3; posMasterNoPrefix: posMaster.posMasterNoPrefix,
shortName = posMaster.orgChild3.orgChild3ShortName; posMasterNo: posMaster.posMasterNo,
} else if ( posMasterNoSuffix: posMaster.posMasterNoSuffix,
posMaster.orgRootId !== null && orgShortname: shortName,
posMaster.orgChild1Id !== null && isSit: posMaster.isSit,
posMaster.orgChild2Id !== null && name: fullname,
posMaster.orgChild3Id !== null profileId: posMaster.current_holder.id,
) { citizenId: posMaster.current_holder.citizenId,
body.node = 4; position: posMaster.current_holder.position,
shortName = posMaster.orgChild4.orgChild4ShortName; };
} }),
);
let node: any = null; return new HttpSuccess({ data: formattedData, total });
let nodeId: any = null; }
if (posMaster.orgChild4Id != null) {
node = 4;
nodeId = posMaster.orgChild4Id;
} else if (posMaster.orgChild3Id != null) {
node = 3;
nodeId = posMaster.orgChild3Id;
} else if (posMaster.orgChild2Id != null) {
node = 2;
nodeId = posMaster.orgChild2Id;
} else if (posMaster.orgChild1Id != null) {
node = 1;
nodeId = posMaster.orgChild1Id;
} else if (posMaster.orgRootId != null) {
node = 0;
nodeId = posMaster.orgRootId;
}
const fullname = posMaster.current_holder.prefix + " " + posMaster.current_holder.firstName + " " + posMaster.current_holder.lastName;
return {
id: posMaster.id,
node: node,
nodeId: nodeId,
orgRootId: posMaster.orgRootId,
orgChild1Id: posMaster.orgChild1Id,
orgChild2Id: posMaster.orgChild2Id,
orgChild3Id: posMaster.orgChild3Id,
orgChild4Id: posMaster.orgChild4Id,
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
orgShortname: shortName,
isSit: posMaster.isSit,
name: fullname,
citizenId: posMaster.current_holder.citizenId,
position: posMaster.current_holder.position,
};
}),
);
return new HttpSuccess({ data: formattedData, total });
}
} }