no message

This commit is contained in:
Kittapath 2024-04-26 18:26:30 +07:00
parent 7f7b676750
commit 23e277c277

View file

@ -226,32 +226,33 @@ export class kpiLinkController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
const [_kpiLink, _total] = await AppDataSource.getRepository(KpiLink)
.createQueryBuilder("kpiLink")
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
.leftJoinAndSelect("kpiLink.positions", "positions")
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiGroup.nameGroupKPI LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("positions.name LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("kpiCapacitys.name LIKE :keyword", { keyword: `%${keyword}%` });
}),
)
.getManyAndCount();
const [kpiLink, total] = await AppDataSource.getRepository(KpiLink) const [kpiLink, total] = await AppDataSource.getRepository(KpiLink)
.createQueryBuilder("kpiLink") .createQueryBuilder("kpiLink")
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup") .leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
.leftJoinAndSelect("kpiLink.positions", "positions") .leftJoinAndSelect("kpiLink.positions", "positions")
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys") .leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
.where( .andWhere("kpiLink.id In (:id)", {
new Brackets((qb) => { id: _kpiLink.map((x) => x.id),
let conditions = []; })
if (keyword) {
conditions.push("kpiGroup.nameGroupKPI LIKE :keyword");
conditions.push("positions.name LIKE :keyword");
conditions.push("kpiCapacitys.name LIKE :keyword");
}
if (conditions.length) {
qb.where(conditions.join(" OR "), { keyword: `%${keyword}%` });
}
}),
)
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.orderBy("kpiLink.createdAt", "ASC") .orderBy("kpiLink.createdAt", "ASC")
.getManyAndCount(); .getManyAndCount();
if (!kpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
const formattedResponse = kpiLink.map((item) => ({ const formattedResponse = kpiLink.map((item) => ({
id: item.id, id: item.id,
groupName: item.kpiGroup.nameGroupKPI, groupName: item.kpiGroup.nameGroupKPI,