zs hai 1 ano
pai
achega
2dd5e483c8

+ 6 - 0
src/controller/platform/project.controller.ts

@@ -39,6 +39,12 @@ export class ProjectController extends BaseController {
     const result = new FVO_project(data);
     return result;
   }
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_project })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.detail(id);
+    return data;
+  }
 
   @Post('/:id')
   @Validate()

+ 7 - 0
src/controller/users/company.controller.ts

@@ -40,6 +40,13 @@ export class CompanyController extends BaseController {
     return result;
   }
 
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_company })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.detail(id);
+    return data;
+  }
+
   @Post('/:id')
   @Validate()
   @ApiResponse({ type: UVAO_company })

+ 15 - 0
src/service/platform/project.service.ts

@@ -3,9 +3,24 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 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';
 type modelType = ReturnModelType<typeof Project>;
 @Provide()
 export class ProjectService extends BaseService<modelType> {
   @InjectEntityModel(Project)
   model: modelType;
+  @InjectEntityModel(Collection)
+  cModel: ReturnModelType<typeof Collection>;
+  //项目详情
+  async detail(id) {
+    const user = this.ctx.user;
+    const data = { userInfo: {}, is_collection: false };
+    const arr = await this.model.findById(id).lean();
+    if (arr) {
+      // 查询是否收藏该项目
+      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+      if (collection) data.is_collection = true;
+    }
+    return { ...arr, ...data };
+  }
 }

+ 17 - 0
src/service/users/company.service.ts

@@ -3,9 +3,26 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 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';
 type modelType = ReturnModelType<typeof Company>;
 @Provide()
 export class CompanyService extends BaseService<modelType> {
   @InjectEntityModel(Company)
   model: modelType;
+
+  @InjectEntityModel(Collection)
+  cModel: ReturnModelType<typeof Collection>;
+
+  // 企业详情
+  async detail(id) {
+    const user = this.ctx.user;
+    const data = { is_collection: false };
+    const arr = await this.model.findById(id).lean();
+    if (arr) {
+      // 查询是否收藏该企业
+      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+      if (collection) data.is_collection = true;
+    }
+    return { ...arr, ...data };
+  }
 }