expert.service.ts 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { Provide } from '@midwayjs/decorator';
  2. import { InjectEntityModel } from '@midwayjs/typegoose';
  3. import { ReturnModelType } from '@typegoose/typegoose';
  4. import { BaseService } from 'free-midway-component';
  5. import { Expert } from '../../entity/users/expert.entity';
  6. import { Collection } from '../../entity/platform/collection.entity';
  7. import { get } from 'lodash';
  8. type modelType = ReturnModelType<typeof Expert>;
  9. @Provide()
  10. export class ExpertService extends BaseService<modelType> {
  11. @InjectEntityModel(Expert)
  12. model: modelType;
  13. @InjectEntityModel(Collection)
  14. cModel: ReturnModelType<typeof Collection>;
  15. // 专家详情
  16. async detail(id) {
  17. const user = this.ctx.user;
  18. const data = { is_collection: false };
  19. const arr = await this.model.findById(id).lean();
  20. if (arr && get(arr, '_id')) {
  21. // 查询是否收藏该专家
  22. const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
  23. if (collection) data.is_collection = true;
  24. }
  25. return { ...arr, ...data };
  26. }
  27. }