zs 1 vuosi sitten
vanhempi
commit
77ba52d132

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

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

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

+ 2 - 1
src/service/platform/project.service.ts

@@ -4,6 +4,7 @@ import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Project } from '../../entity/platform/project.entity';
 import { Collection } from '../../entity/platform/collection.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Project>;
 @Provide()
 export class ProjectService extends BaseService<modelType> {
@@ -16,7 +17,7 @@ export class ProjectService extends BaseService<modelType> {
     const user = this.ctx.user;
     const data = { userInfo: {}, is_collection: false };
     const arr = await this.model.findById(id).lean();
-    if (arr) {
+    if (arr && get(arr, '_id')) {
       // 查询是否收藏该项目
       const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
       if (collection) data.is_collection = true;

+ 2 - 1
src/service/users/company.service.ts

@@ -4,6 +4,7 @@ import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Company } from '../../entity/users/company.entity';
 import { Collection } from '../../entity/platform/collection.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Company>;
 @Provide()
 export class CompanyService extends BaseService<modelType> {
@@ -18,7 +19,7 @@ export class CompanyService extends BaseService<modelType> {
     const user = this.ctx.user;
     const data = { is_collection: false };
     const arr = await this.model.findById(id).lean();
-    if (arr) {
+    if (arr && get(arr, '_id')) {
       // 查询是否收藏该企业
       const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
       if (collection) data.is_collection = true;

+ 2 - 1
src/service/users/expert.service.ts

@@ -4,6 +4,7 @@ import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Expert } from '../../entity/users/expert.entity';
 import { Collection } from '../../entity/platform/collection.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Expert>;
 @Provide()
 export class ExpertService extends BaseService<modelType> {
@@ -17,7 +18,7 @@ export class ExpertService extends BaseService<modelType> {
     const user = this.ctx.user;
     const data = { is_collection: false };
     const arr = await this.model.findById(id).lean();
-    if (arr) {
+    if (arr && get(arr, '_id')) {
       // 查询是否收藏该专家
       const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
       if (collection) data.is_collection = true;