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

View File

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