Procházet zdrojové kódy

修改查询用户条件

zs před 10 měsíci
rodič
revize
8d8a858aee

+ 5 - 3
src/service/platform/achievement.service.ts

@@ -56,9 +56,11 @@ export class AchievementService extends BaseService<modelType> {
       if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
     }
     if (arr && get(arr, '_id')) {
-      // 查询是否收藏该成果
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        // 查询是否收藏该成果
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 5 - 3
src/service/platform/demand.service.ts

@@ -46,9 +46,11 @@ export class DemandService extends BaseService<modelType> {
       if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
     }
     if (arr && get(arr, '_id')) {
-      // 查询是否收藏该需求
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        // 查询是否收藏该需求
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 4 - 2
src/service/platform/match.service.ts

@@ -21,8 +21,10 @@ export class MatchService extends BaseService<modelType> {
     const arr = await this.model.findById(id).lean();
     if (arr && get(arr, '_id')) {
       // 查询是否收藏该比赛
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 5 - 3
src/service/platform/project.service.ts

@@ -46,9 +46,11 @@ export class ProjectService extends BaseService<modelType> {
       if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
     }
     if (arr && get(arr, '_id')) {
-      // 查询是否收藏该项目
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        // 查询是否收藏该项目
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 4 - 2
src/service/platform/supply.service.ts

@@ -47,8 +47,10 @@ export class SupplyService extends BaseService<modelType> {
     }
     if (arr && get(arr, '_id')) {
       // 查询是否收藏该需求
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 5 - 3
src/service/users/company.service.ts

@@ -35,9 +35,11 @@ export class CompanyService extends BaseService<modelType> {
     const data = { is_collection: false };
     const arr = await this.model.findById(id).lean();
     if (arr && get(arr, '_id')) {
-      // 查询是否收藏该企业
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        // 查询是否收藏该企业
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }

+ 5 - 3
src/service/users/expert.service.ts

@@ -33,9 +33,11 @@ export class ExpertService extends BaseService<modelType> {
     const data = { is_collection: false };
     const arr = await this.model.findById(id).lean();
     if (arr && get(arr, '_id')) {
-      // 查询是否收藏该专家
-      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      if (collection) data.is_collection = true;
+      if (user && user._id) {
+        // 查询是否收藏该专家
+        const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+        if (collection) data.is_collection = true;
+      }
     }
     return { ...arr, ...data };
   }