Skip to content

Commit

Permalink
fix: 修改排序接口联调bug (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
luch1994 authored and sudoooooo committed Jan 23, 2024
1 parent 0778b68 commit 203537a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions server/src/apps/surveyManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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参数格式不正确');
}
Expand Down Expand Up @@ -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;
}, {});
}
Expand Down
10 changes: 3 additions & 7 deletions server/src/apps/surveyManage/service/surveyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 203537a

Please sign in to comment.