后台:添加权限,添加排序

This commit is contained in:
luying
2021-06-08 20:34:36 +08:00
parent d1a4754fc5
commit 61dc5ea362
4 changed files with 29 additions and 21 deletions

View File

@@ -91,7 +91,7 @@ export default class Activity extends BaseModel {
}
//查询
public static async findByCondition(page: number, pageSize: number, type: number = 0, groupId: number = 0, current: boolean = false, activityId: number = 0) {
public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, type: number = 0, groupId: number = 0, current: boolean = false, activityId: number = 0) {
let searchObj = {};
if (type != 0) searchObj['type'] = type;
if (groupId != 0) searchObj['groupId'] = groupId;
@@ -100,7 +100,15 @@ export default class Activity extends BaseModel {
searchObj['beginTime'] = { $lte: new Date };
searchObj['endTime'] = { $gte: new Date };
}
const result: ActivityModelType[] = await ActivityModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort({ updatedAt: -1 }).lean();
let sort = {};
if(sortField && sortOrder) {
if(sortOrder == 'ascend') {
sort[sortField] = 1;
} else if (sortOrder == 'descend') {
sort[sortField] = -1;
}
}
const result: ActivityModelType[] = await ActivityModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean();
return result;
}