import { Provide } from '@midwayjs/decorator'; 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'; import { get } from 'lodash'; type modelType = ReturnModelType; @Provide() export class ExpertService extends BaseService { @InjectEntityModel(Expert) model: modelType; @InjectEntityModel(Collection) cModel: ReturnModelType; // 专家详情 async detail(id) { const user = this.ctx.user; 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; } return { ...arr, ...data }; } }