zs 1 vuosi sitten
vanhempi
commit
c669c60d88

+ 8 - 0
src/controller/platform/collection.controller.ts

@@ -54,6 +54,14 @@ export class CollectionController extends BaseController {
     await this.service.delete(id);
     return 'ok';
   }
+
+  @Post('/cancel')
+  @Validate()
+  @ApiResponse({ type: CVO_collection })
+  async cancel(@Body() data: CDTO_collection) {
+    await this.service.cancel(data);
+    return 'ok';
+  }
   async createMany(...args: any[]) {
     throw new Error('Method not implemented.');
   }

+ 13 - 1
src/controller/platform/demand.controller.ts

@@ -31,6 +31,13 @@ export class DemandController extends BaseController {
     const total = await this.service.count(filter);
     return { data, total };
   }
+  @Get('/list')
+  async list(@Query() filter) {
+    const list = await this.service.list(filter);
+    const data = list.data;
+    const total = list.total;
+    return { data, total };
+  }
 
   @Get('/:id')
   @ApiResponse({ type: FVO_demand })
@@ -39,7 +46,12 @@ export class DemandController extends BaseController {
     const result = new FVO_demand(data);
     return result;
   }
-
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_demand })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.detail(id);
+    return data;
+  }
   @Post('/:id')
   @Validate()
   @ApiResponse({ type: UVAO_demand })

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

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

+ 5 - 0
src/service/platform/collection.service.ts

@@ -8,4 +8,9 @@ type modelType = ReturnModelType<typeof Collection>;
 export class CollectionService extends BaseService<modelType> {
   @InjectEntityModel(Collection)
   model: modelType;
+  // 取消收藏
+  async cancel(data) {
+    const { user, source } = data;
+    await this.model.deleteOne({ user, source });
+  }
 }

+ 36 - 0
src/service/platform/demand.service.ts

@@ -3,9 +3,45 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Demand } from '../../entity/platform/demand.entity';
+import { Collection } from '../../entity/platform/collection.entity';
+import { User } from '../../entity/system/user.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Demand>;
 @Provide()
 export class DemandService extends BaseService<modelType> {
   @InjectEntityModel(Demand)
   model: modelType;
+  @InjectEntityModel(Collection)
+  cModel: ReturnModelType<typeof Collection>;
+  @InjectEntityModel(User)
+  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();
+    for (const val of data) {
+      if (get(val, 'user')) {
+        // 查询需求发布者
+        const userData = await this.uModel.findById(val.user).lean();
+        if (userData) Object.assign(val, { userName: userData.nick_name });
+      }
+    }
+    const total = await this.model.count(condition);
+    return { data, total };
+  }
+  // 需求详情
+  async detail(id) {
+    const user = this.ctx.user;
+    const data = { userInfo: {}, is_collection: false };
+    const arr = await this.model.findById(id).lean();
+    if (arr && get(arr, 'user')) {
+      // 查询需求发布者
+      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;
+    }
+    return { ...arr, ...data };
+  }
 }

+ 16 - 0
src/service/users/expert.service.ts

@@ -3,9 +3,25 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 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';
 type modelType = ReturnModelType<typeof Expert>;
 @Provide()
 export class ExpertService extends BaseService<modelType> {
   @InjectEntityModel(Expert)
   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 };
+  }
 }