|
@@ -3,9 +3,24 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
import { BaseService } from 'free-midway-component';
|
|
|
import { Project } from '../../entity/platform/project.entity';
|
|
|
+import { Collection } from '../../entity/platform/collection.entity';
|
|
|
type modelType = ReturnModelType<typeof Project>;
|
|
|
@Provide()
|
|
|
export class ProjectService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(Project)
|
|
|
model: modelType;
|
|
|
+ @InjectEntityModel(Collection)
|
|
|
+ cModel: ReturnModelType<typeof Collection>;
|
|
|
+ //项目详情
|
|
|
+ async detail(id) {
|
|
|
+ const user = this.ctx.user;
|
|
|
+ const data = { userInfo: {}, is_collection: false };
|
|
|
+ const arr = await this.model.findById(id).lean();
|
|
|
+ if (arr) {
|
|
|
+ // 查询是否收藏该项目
|
|
|
+ const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
|
|
|
+ if (collection) data.is_collection = true;
|
|
|
+ }
|
|
|
+ return { ...arr, ...data };
|
|
|
+ }
|
|
|
}
|