|
@@ -2,6 +2,7 @@ import { Provide } from '@midwayjs/core';
|
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
import { Equal, In, Repository } from 'typeorm';
|
|
|
import { BaseService } from '../../frame/BaseService';
|
|
|
+import { Collection } from '../../entity/platform/collection.entity';
|
|
|
import { Expert } from '../../entity/users/expert.entity';
|
|
|
import { get, pick } from 'lodash';
|
|
|
@Provide()
|
|
@@ -9,8 +10,8 @@ export class ExpertService extends BaseService<Expert> {
|
|
|
@InjectEntityModel(Expert)
|
|
|
model: Repository<Expert>;
|
|
|
|
|
|
- // @InjectEntityModel(Collection)
|
|
|
- // cModel: Repository<Collection>;
|
|
|
+ @InjectEntityModel(Collection)
|
|
|
+ cModel: Repository<Collection>;
|
|
|
|
|
|
// 企业列表
|
|
|
async list(query: any) {
|
|
@@ -31,14 +32,13 @@ export class ExpertService extends BaseService<Expert> {
|
|
|
|
|
|
// 企业详情
|
|
|
async detail(id) {
|
|
|
- // const user = this.ctx.user;
|
|
|
+ const user = this.ctx.user;
|
|
|
const data = { is_collection: false };
|
|
|
- // const arr = await this.model.findById(id).lean();
|
|
|
const arr = await this.model.findOne({ where: { id: Equal(id) } });
|
|
|
- if (arr && get(arr, 'id')) {
|
|
|
+ if (arr && get(arr, 'id') && user) {
|
|
|
// TODO: 查询是否收藏该企业
|
|
|
- // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
|
|
|
- // if (collection) data.is_collection = true;
|
|
|
+ const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
|
|
|
+ if (collection) data.is_collection = true;
|
|
|
}
|
|
|
return { ...arr, ...data };
|
|
|
}
|