api profile/search

This commit is contained in:
AdisakKanthawilang 2024-05-21 13:23:42 +07:00
parent f6bdfce063
commit 3b68f7670f

View file

@ -2833,7 +2833,6 @@ export class PositionController extends Controller {
};
}
}
console.log("3333333333333333333333333333333");
const [posMaster, total] = await AppDataSource.getRepository(EmployeePosMaster)
.createQueryBuilder("posMaster")
@ -2861,7 +2860,6 @@ export class PositionController extends Controller {
.orderBy("posMaster.posMasterOrder", "ASC")
.getManyAndCount();
console.log("2222222222222222222222222222222222");
const formattedData = await Promise.all(
posMaster.map(async (posMaster) => {
let shortName = "";
@ -2960,7 +2958,174 @@ export class PositionController extends Controller {
};
}),
);
console.log("1111111111111111111111111111111111111");
return new HttpSuccess({ data: formattedData, total });
}
/**
* API
*
* @summary
*
*/
@Post("profile/search")
async searchProfile(
@Body()
body: {
isAll: boolean;
node: number;
nodeId: string;
},
) {
let typeCondition: any = {};
if (body.isAll == false) {
if (body.node === 0) {
typeCondition = {
orgRootId: body.nodeId,
orgChild1Id: IsNull(),
};
} else if (body.node === 1) {
typeCondition = {
orgChild1Id: body.nodeId,
orgChild2Id: IsNull(),
};
} else if (body.node === 2) {
typeCondition = {
orgChild2Id: body.nodeId,
orgChild3Id: IsNull(),
};
} else if (body.node === 3) {
typeCondition = {
orgChild3Id: body.nodeId,
orgChild4Id: IsNull(),
};
} else if (body.node === 4) {
typeCondition = {
orgChild4Id: body.nodeId,
};
}
} else {
if (body.node === 0) {
typeCondition = {
orgRootId: body.nodeId,
};
} else if (body.node === 1) {
typeCondition = {
orgChild1Id: body.nodeId,
};
} else if (body.node === 2) {
typeCondition = {
orgChild2Id: body.nodeId,
};
} else if (body.node === 3) {
typeCondition = {
orgChild3Id: body.nodeId,
};
} else if (body.node === 4) {
typeCondition = {
orgChild4Id: body.nodeId,
};
}
}
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
.where("posMaster.current_holderId IS NOT NULL")
.andWhere(
new Brackets((qb) => {
qb.orWhere(typeCondition);
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.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;
}
let node: any = null;
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;
}
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,
};
}),
);
return new HttpSuccess({ data: formattedData, total });
}
}