sort probation
This commit is contained in:
parent
b99ce45f86
commit
444bbf71b4
2 changed files with 64 additions and 12 deletions
|
|
@ -147,11 +147,13 @@ export class PersonalController extends Controller {
|
|||
*/
|
||||
@Get("list")
|
||||
async ListPersonal(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() status: string = "",
|
||||
@Query() keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser
|
||||
@Query("sortBy") sortBy?: string,
|
||||
@Query("descending") descending?: boolean
|
||||
) {
|
||||
try {
|
||||
// await new permission().PermissionList(request, "SYS_PROBATION");
|
||||
|
|
@ -215,7 +217,7 @@ export class PersonalController extends Controller {
|
|||
|
||||
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(Personal)
|
||||
let query = await AppDataSource.getRepository(Personal)
|
||||
.createQueryBuilder("personal")
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
|
|
@ -303,10 +305,37 @@ export class PersonalController extends Controller {
|
|||
);
|
||||
})
|
||||
)
|
||||
.orderBy("updatedAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
if (sortBy) {
|
||||
if(sortBy === "position_line"){
|
||||
query = query.orderBy(
|
||||
`personal.positionName`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(sortBy === "position_level"){
|
||||
query = query.orderBy(
|
||||
`personal.positionLevelName`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(sortBy === "position_type"){
|
||||
query = query.orderBy(
|
||||
`personal.positionTypeName`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else{
|
||||
query = query.orderBy(
|
||||
`personal.${sortBy}`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}
|
||||
}else{
|
||||
query = query.orderBy("updatedAt", "DESC")
|
||||
}
|
||||
|
||||
const [lists, total] = await query
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
|
||||
if (!lists) {
|
||||
throw new HttpError(
|
||||
|
|
|
|||
|
|
@ -119,11 +119,13 @@ export class SurveyController extends Controller {
|
|||
*/
|
||||
@Get("/admin")
|
||||
async GetSurveyAdmin(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() year: number = new Date().getFullYear(),
|
||||
@Query() keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser
|
||||
@Query("sortBy") sortBy?: string,
|
||||
@Query("descending") descending?: boolean
|
||||
) {
|
||||
try {
|
||||
const start = new Date("01-01-" + year);
|
||||
|
|
@ -131,7 +133,7 @@ export class SurveyController extends Controller {
|
|||
|
||||
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(Survey)
|
||||
let query = await AppDataSource.getRepository(Survey)
|
||||
.createQueryBuilder("survey")
|
||||
.leftJoinAndSelect("survey.personal", "personal")
|
||||
.where(
|
||||
|
|
@ -157,10 +159,31 @@ export class SurveyController extends Controller {
|
|||
);
|
||||
})
|
||||
)
|
||||
.orderBy("survey.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
if (sortBy) {
|
||||
if(sortBy === "fullname"){
|
||||
query = query
|
||||
.orderBy(`personal.prefixName`,descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`personal.firstName`,descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`personal.lastName`,descending ? "DESC" : "ASC");
|
||||
}else if(sortBy === "position"){
|
||||
query = query
|
||||
.orderBy(`personal.positionName`,descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`personal.positionLevelName`,descending ? "DESC" : "ASC")
|
||||
}else{
|
||||
query = query.orderBy(
|
||||
`survey.${sortBy}`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}
|
||||
}else{
|
||||
query = query.orderBy("survey.createdAt", "DESC")
|
||||
}
|
||||
|
||||
const [lists, total] = await query
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const data = lists.map((item) => {
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue