sort api/v1/evaluation/user
This commit is contained in:
parent
3174f23a14
commit
cbeac798dd
1 changed files with 12 additions and 1 deletions
|
|
@ -269,10 +269,12 @@ export class EvaluationController {
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
status?: string[];
|
status?: string[];
|
||||||
|
sortBy?: string,
|
||||||
|
descending?: boolean,
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
|
let query = await AppDataSource.getRepository(Evaluation)
|
||||||
.createQueryBuilder("evaluation")
|
.createQueryBuilder("evaluation")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
|
|
@ -293,6 +295,15 @@ export class EvaluationController {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("evaluation.lastUpdatedAt", "DESC")
|
.orderBy("evaluation.lastUpdatedAt", "DESC")
|
||||||
|
|
||||||
|
if (body.sortBy) {
|
||||||
|
query = query.orderBy(
|
||||||
|
`evaluation.${body.sortBy}`,
|
||||||
|
body.descending ? "DESC" : "ASC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [evaluation, total] = await query
|
||||||
.skip((body.page - 1) * body.pageSize)
|
.skip((body.page - 1) * body.pageSize)
|
||||||
.take(body.pageSize)
|
.take(body.pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue