import { Inject, Provide } from '@midwayjs/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { Repository } from 'typeorm'; import { BaseServiceV2 } from '../../frame/BaseServiceV2'; import { MatchExt } from '../../entity/match/matchExt.entity'; import { UserService } from '../system/user.service'; import { get, pick } from 'lodash'; import { MatchService } from '../platform/match.service'; import { MatchRegistrationService } from './matchRegistration.service'; import { ErrorCode, ServiceError } from '../../error/service.error'; @Provide() export class MatchExtService extends BaseServiceV2 { @InjectEntityModel(MatchExt) model: Repository; @Inject() matchService: MatchService; @Inject() matchRegService: MatchRegistrationService; @Inject() userService: UserService; /**获取用户信息的属性 */ async getUserProps(id, props) { if (!props) return; const user = await this.userService.fetch({ id }); if (!user) return; const obj = pick(user, props); return obj; } /** * 赛事状态检查 * @param id 赛事id * @param status 赛事应处于的状态码 */ async checkMatchStatus(id, status) { const data = await this.matchService.fetch({ id }); if (!data) { throw new ServiceError(ErrorCode.MATCH_NOT_FOUND); } const data_status = get(data, 'status'); if (status !== data_status) { // 抛出异常: 赛事状态不符合要求. throw new ServiceError(ErrorCode.MATCH_STATUS_ERROR); } return true; } /** * 赛事拓展状态检查 * @param match_id 赛事拓展id * @param status 赛事拓展应处于的状态码 */ async checkMatchExtStatus(match_id, status) { const data = await this.fetch({ match_id }); if (!data) { throw new ServiceError(ErrorCode.MATCH_NOT_FOUND); } const data_status = get(data, 'status'); if (status !== data_status) { // 抛出异常: 赛事拓展状态不符合要求. throw new ServiceError(ErrorCode.MATCH_EXT_STATUS_ERROR); } return true; } /** * 赛事报名人员状态检查 * @param id 赛事报名id * @param status 赛事报名应处于的状态码 */ async checkMatchRegStatus(id, status) { const data = await this.matchRegService.fetch({ id }); if (!data) { throw new ServiceError(ErrorCode.MATCH_REG_NOT_FOUND); } const data_status = get(data, 'status'); if (status !== data_status) { // 抛出异常: 赛事报名状态不符合要求. throw new ServiceError(ErrorCode.MATCH_REG_STATUS_ERROR); } return true; } }