fix: 修改排序接口联调bug (#53)

This commit is contained in:
luch 2024-01-23 21:49:27 +08:00 committed by GitHub
parent b6e9c05d1f
commit 4031266ce8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View File

@ -114,14 +114,14 @@ export default class SurveyManage {
let filter = {}, order = {};
if (condition.filter) {
try {
filter = this.getFilter(JSON.parse(condition.filter));
filter = this.getFilter(JSON.parse(decodeURIComponent(condition.filter)));
} catch (error) {
throw new CommonError('filter参数格式不正确');
}
}
if (condition.order) {
try {
order = this.getOrder(JSON.parse(condition.order));
order = this.getOrder(JSON.parse(decodeURIComponent(condition.order)));
} catch (error) {
throw new CommonError('order参数格式不正确');
}
@ -178,13 +178,13 @@ export default class SurveyManage {
private getOrder(order) {
const allowOrderField = ['createDate', 'updateDate'];
const allowOrderFields = ['createDate', 'updateDate', 'curStatus.date'];
const orderList = JSON.parse(order).filter((orderItem) =>
allowOrderField.includes(orderItem.field),
const orderList = order.filter((orderItem) =>
allowOrderFields.includes(orderItem.field),
);
return orderList.reduce((pre, cur) => {
pre[cur.field] = cur.value;
pre[cur.field] = cur.value === 1 ? 1 : -1;
return pre;
}, {});
}

View File

@ -182,13 +182,9 @@ class SurveyService {
},
condition.filter,
);
const order = Object.assign(
{},
{
createDate: -1,
},
condition.order,
) as Sort;
const order = condition.order && Object.keys(condition.order).length > 0 ? condition.order as Sort : {
createDate: -1,
} as Sort;
const data = await surveyMeta.find(query)
.sort(order)
.limit(condition.pageSize)