sort admin

This commit is contained in:
adisak 2025-09-23 11:54:17 +07:00
parent 57c9a84c40
commit d999241536
3 changed files with 54 additions and 10 deletions

View file

@ -116,6 +116,8 @@ 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,
) {
let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
const orgRevisionPublish = await this.orgRevisionRepository
@ -123,7 +125,7 @@ export class ProfileEditController extends Controller {
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
let query = await AppDataSource.getRepository(ProfileEdit)
.createQueryBuilder("ProfileEdit")
.leftJoinAndSelect("ProfileEdit.profile", "profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
@ -214,10 +216,27 @@ export class ProfileEditController extends Controller {
);
}),
)
.orderBy("ProfileEdit.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
.orderBy("ProfileEdit.createdAt", "DESC")
if (sortBy) {
if(sortBy == "fullname"){
query = query.orderBy(
`profile.firstName`,
descending ? "DESC" : "ASC"
);
}else{
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,
idcard: item.profile.citizenId,