sort ข้อมูลการประเมิน

This commit is contained in:
Adisak 2025-09-29 15:42:19 +07:00
parent ab661f42e2
commit 50da2b4e70
6 changed files with 80 additions and 8 deletions

View file

@ -348,18 +348,29 @@ export class kpiCapacityController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("type") type?: string,
@Query("keyword") keyword?: string,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
let query = await AppDataSource.getRepository(KpiCapacity)
.createQueryBuilder("kpiCapacity")
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")
.andWhere(keyword == undefined ? "1=1" : [{ name: Like(`%${keyword}%`) }])
.andWhere(type == undefined ? "1=1" : { type: type })
.orderBy("kpiCapacity.createdAt", "ASC")
if (sortBy) {
query = query.orderBy(
`kpiCapacity.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [kpiCapacity, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const mapFormula = kpiCapacity.map((item) => ({
id: item.id,
type: item.type,