collection.service.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Inject, Provide } from '@midwayjs/core';
  2. import { InjectEntityModel } from '@midwayjs/typeorm';
  3. import { Equal, Repository } from 'typeorm';
  4. import { Collection } from '../../entity/platform/collection.entity';
  5. import { BaseServiceV2 } from '../../frame/BaseServiceV2';
  6. import { MatchService } from '../platform/match.service';
  7. import { AchievementService } from '../platform/achievement.service';
  8. import { SupplyService } from '../platform/supply.service';
  9. import { SupportService } from '../platform/support.service';
  10. import { ProjectService } from '../platform/project.service';
  11. import { FootplateService } from '../platform/footplate.service';
  12. import { NewsService } from '../platform/news.service';
  13. import { ExpertService } from '../../service/users/expert.service';
  14. import { DemandService } from '../platform/demand.service';
  15. import { CompanyService } from '../../service/users/company.service';
  16. import { IncubatorService } from '../users/incubator.service';
  17. @Provide()
  18. export class CollectionService extends BaseServiceV2 {
  19. getQueryColumnsOpera(): object {
  20. return {};
  21. }
  22. @InjectEntityModel(Collection)
  23. model: Repository<Collection>;
  24. @Inject()
  25. match: MatchService;
  26. @Inject()
  27. achievement: AchievementService;
  28. @Inject()
  29. supply: SupplyService;
  30. @Inject()
  31. support: SupportService;
  32. @Inject()
  33. project: ProjectService;
  34. @Inject()
  35. footplate: FootplateService;
  36. @Inject()
  37. news: NewsService;
  38. @Inject()
  39. expert: ExpertService;
  40. @Inject()
  41. demand: DemandService;
  42. @Inject()
  43. company: CompanyService;
  44. @Inject()
  45. incubator: IncubatorService;
  46. // 转化来源数据名称
  47. async fillScource(data) {
  48. const { type, source } = data;
  49. const dataRes = await this[type].fetch({ id: source });
  50. if (dataRes) data = { ...data, source_name: dataRes.name || dataRes.title, status: '1' };
  51. else data = { ...data, source_name: '已失效', status: '-1' };
  52. return data;
  53. }
  54. // 取消收藏
  55. async cancel(data) {
  56. const { user, source, type } = data;
  57. const d = await this.model.findOne({ where: { user: Equal(user), source: Equal(source), type: Equal(type) } });
  58. await this.model.delete(d.id);
  59. }
  60. }