|
@@ -17,8 +17,27 @@ export class DemandService extends BaseService<modelType> {
|
|
|
uModel: ReturnModelType<typeof User>;
|
|
|
// 需求列表
|
|
|
async list(query) {
|
|
|
- const { skip = 0, limit = 0, ...condition } = query;
|
|
|
- const data = await this.model.find(condition).skip(skip).limit(limit).lean();
|
|
|
+ const { skip = 0, limit = 0, is_use, status, ...condition } = query;
|
|
|
+ const { one, two, thr, four } = condition;
|
|
|
+ const info: any = { is_use, status };
|
|
|
+ // 如果 one 不是一个数组,你可能需要手动处理
|
|
|
+ if (one) {
|
|
|
+ if (!Array.isArray(one)) info.field = one;
|
|
|
+ else info.field = { $all: one };
|
|
|
+ }
|
|
|
+ if (two) {
|
|
|
+ if (!Array.isArray(two)) info.method = two;
|
|
|
+ else info.method = { $all: two };
|
|
|
+ }
|
|
|
+ if (thr) {
|
|
|
+ if (!Array.isArray(thr)) info.area = thr;
|
|
|
+ else info.area = { $all: thr };
|
|
|
+ }
|
|
|
+ if (four) {
|
|
|
+ if (!Array.isArray(four)) info.demand_status = four;
|
|
|
+ else info.demand_status = { $all: four };
|
|
|
+ }
|
|
|
+ const data = await this.model.find(info).skip(skip).limit(limit).lean();
|
|
|
for (const val of data) {
|
|
|
if (get(val, 'user')) {
|
|
|
// 查询需求发布者
|
|
@@ -26,7 +45,7 @@ export class DemandService extends BaseService<modelType> {
|
|
|
if (userData) Object.assign(val, { userName: userData.nick_name });
|
|
|
}
|
|
|
}
|
|
|
- const total = await this.model.count(condition);
|
|
|
+ const total = await this.model.count(info);
|
|
|
return { data, total };
|
|
|
}
|
|
|
// 需求详情
|