sort org/profile/edit/user
This commit is contained in:
parent
a61cd6f060
commit
3cad6dbf25
1 changed files with 15 additions and 4 deletions
|
|
@ -39,13 +39,15 @@ export class ProfileEditController extends Controller {
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword: string = "",
|
@Query("keyword") keyword: string = "",
|
||||||
@Query("status") status: string = "",
|
@Query("status") status: string = "",
|
||||||
|
@Query("sortBy") sortBy?: string,
|
||||||
|
@Query("descending") descending?: boolean,
|
||||||
) {
|
) {
|
||||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
}
|
}
|
||||||
|
|
||||||
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
let query = await AppDataSource.getRepository(ProfileEdit)
|
||||||
.createQueryBuilder("ProfileEdit")
|
.createQueryBuilder("ProfileEdit")
|
||||||
.leftJoinAndSelect("ProfileEdit.profile", "profile")
|
.leftJoinAndSelect("ProfileEdit.profile", "profile")
|
||||||
.where((qb) => {
|
.where((qb) => {
|
||||||
|
|
@ -74,9 +76,18 @@ export class ProfileEditController extends Controller {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("ProfileEdit.createdAt", "DESC")
|
.orderBy("ProfileEdit.createdAt", "DESC")
|
||||||
.skip((page - 1) * pageSize)
|
|
||||||
.take(pageSize)
|
if (sortBy) {
|
||||||
.getManyAndCount();
|
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) => ({
|
const _data = getProfileEdit.map((item) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue