no message
This commit is contained in:
parent
7f7b676750
commit
23e277c277
1 changed files with 17 additions and 16 deletions
|
|
@ -226,32 +226,33 @@ export class kpiLinkController extends Controller {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@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)
|
||||
.createQueryBuilder("kpiLink")
|
||||
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
|
||||
.leftJoinAndSelect("kpiLink.positions", "positions")
|
||||
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
|
||||
.where(
|
||||
new Brackets((qb) => {
|
||||
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}%` });
|
||||
}
|
||||
}),
|
||||
)
|
||||
.andWhere("kpiLink.id In (:id)", {
|
||||
id: _kpiLink.map((x) => x.id),
|
||||
})
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.orderBy("kpiLink.createdAt", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
if (!kpiLink) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
|
||||
}
|
||||
const formattedResponse = kpiLink.map((item) => ({
|
||||
id: item.id,
|
||||
groupName: item.kpiGroup.nameGroupKPI,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue