|
@@ -3,9 +3,31 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
import { BaseService } from 'free-midway-component';
|
|
|
import { Achievement } from '../../entity/platform/achievement.entity';
|
|
|
+import { Collection } from '../../entity/platform/collection.entity';
|
|
|
+import { User } from '../../entity/system/user.entity';
|
|
|
+import { get } from 'lodash';
|
|
|
type modelType = ReturnModelType<typeof Achievement>;
|
|
|
@Provide()
|
|
|
export class AchievementService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(Achievement)
|
|
|
model: modelType;
|
|
|
+ @InjectEntityModel(Collection)
|
|
|
+ cModel: ReturnModelType<typeof Collection>;
|
|
|
+ @InjectEntityModel(User)
|
|
|
+ uModel: ReturnModelType<typeof User>;
|
|
|
+ // 成果详情
|
|
|
+ async detail(id) {
|
|
|
+ const user = this.ctx.user;
|
|
|
+ const data = { userInfo: {}, is_collection: false };
|
|
|
+ const arr = await this.model.findById(id).lean();
|
|
|
+ if (arr && get(arr, 'user')) {
|
|
|
+ // 查询成果发布者
|
|
|
+ const userData = await this.uModel.findById(arr.user).lean();
|
|
|
+ if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
|
|
|
+ // 查询是否收藏该成果
|
|
|
+ const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
|
|
|
+ if (collection) data.is_collection = true;
|
|
|
+ }
|
|
|
+ return { ...arr, ...data };
|
|
|
+ }
|
|
|
}
|