|
@@ -3,9 +3,27 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
import { BaseService } from 'free-midway-component';
|
|
import { BaseService } from 'free-midway-component';
|
|
import { Match } from '../../entity/platform/match.entity';
|
|
import { Match } from '../../entity/platform/match.entity';
|
|
|
|
+import { Collection } from 'mongoose';
|
|
|
|
+import { get } from 'lodash';
|
|
type modelType = ReturnModelType<typeof Match>;
|
|
type modelType = ReturnModelType<typeof Match>;
|
|
@Provide()
|
|
@Provide()
|
|
export class MatchService extends BaseService<modelType> {
|
|
export class MatchService extends BaseService<modelType> {
|
|
@InjectEntityModel(Match)
|
|
@InjectEntityModel(Match)
|
|
model: modelType;
|
|
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 && get(arr, '_id')) {
|
|
|
|
+ // 查询是否收藏该比赛
|
|
|
|
+ const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
|
|
|
|
+ if (collection) data.is_collection = true;
|
|
|
|
+ }
|
|
|
|
+ return { ...arr, ...data };
|
|
|
|
+ }
|
|
}
|
|
}
|