sort org/profile/edit/user

This commit is contained in:
AdisakKanthawilang 2025-09-12 10:09:48 +07:00
parent a61cd6f060
commit 3cad6dbf25

View file

@ -39,13 +39,15 @@ export class ProfileEditController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword: string = "",
@Query("status") status: string = "",
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
let query = await AppDataSource.getRepository(ProfileEdit)
.createQueryBuilder("ProfileEdit")
.leftJoinAndSelect("ProfileEdit.profile", "profile")
.where((qb) => {
@ -74,9 +76,18 @@ export class ProfileEditController extends Controller {
}),
)
.orderBy("ProfileEdit.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
if (sortBy) {
query = query.orderBy(
`ProfileEdit.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [getProfileEdit, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const _data = getProfileEdit.map((item) => ({
id: item.id,