|
@@ -0,0 +1,73 @@
|
|
|
+import { Inject, Provide } from '@midwayjs/core';
|
|
|
+import { Context } from '@midwayjs/koa';
|
|
|
+import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
+import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
+import { Collection } from '../entity/platform/collection.entity';
|
|
|
+import { Achievement } from '../entity/platform/achievement.entity';
|
|
|
+import { Demand } from '../entity/platform/demand.entity';
|
|
|
+import { Match } from '../entity/platform/match.entity';
|
|
|
+import { Expert } from '../entity/users/expert.entity';
|
|
|
+import { Company } from '../entity/users/company.entity';
|
|
|
+import { Project } from '../entity/platform/project.entity';
|
|
|
+@Provide()
|
|
|
+export class ToolService {
|
|
|
+ @Inject()
|
|
|
+ ctx: Context;
|
|
|
+ @InjectEntityModel(Collection)
|
|
|
+ cModel: ReturnModelType<typeof Collection>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Achievement)
|
|
|
+ aModel: ReturnModelType<typeof Achievement>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Demand)
|
|
|
+ dModel: ReturnModelType<typeof Demand>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Project)
|
|
|
+ pModel: ReturnModelType<typeof Project>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Match)
|
|
|
+ mModel: ReturnModelType<typeof Match>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Expert)
|
|
|
+ eModel: ReturnModelType<typeof Expert>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Company)
|
|
|
+ companyModel: ReturnModelType<typeof Company>;
|
|
|
+
|
|
|
+ // 收藏总数
|
|
|
+ async getCollectionTotal() {
|
|
|
+ const user = this.ctx.user;
|
|
|
+ const actList = [
|
|
|
+ { label: '成果', value: 'achievement' },
|
|
|
+ { label: '需求', value: 'demand' },
|
|
|
+ { label: '项目', value: 'project' },
|
|
|
+ { label: '赛事', value: 'match' },
|
|
|
+ { label: '企业', value: 'company' },
|
|
|
+ { label: '专家', value: 'expert' },
|
|
|
+ ];
|
|
|
+ for (const val of actList) {
|
|
|
+ const total = await this.cModel.count({ user, type: val.value }).lean();
|
|
|
+ val.label = val.label + `(${total})`;
|
|
|
+ }
|
|
|
+ return actList;
|
|
|
+ }
|
|
|
+ // 我的收藏
|
|
|
+ async getCollection(filter) {
|
|
|
+ const user = this.ctx.user;
|
|
|
+ const { skip = 0, limit = 0, type } = filter;
|
|
|
+ let model;
|
|
|
+ const data = [];
|
|
|
+ if (type === 'achievement') model = this.aModel;
|
|
|
+ if (type === 'demand') model = this.dModel;
|
|
|
+ if (type === 'project') model = this.pModel;
|
|
|
+ if (type === 'match') model = this.mModel;
|
|
|
+ if (type === 'company') model = this.companyModel;
|
|
|
+ if (type === 'expert') model = this.eModel;
|
|
|
+ const list = await this.cModel.find({ user, type }).skip(skip).limit(limit).lean();
|
|
|
+ for (const val of list) {
|
|
|
+ data.push(await model.findById(val.source).lean());
|
|
|
+ }
|
|
|
+ const total = await this.cModel.count({ user, type }).lean();
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
+}
|