|
@@ -1,11 +1,89 @@
|
|
import { Provide } from '@midwayjs/decorator';
|
|
import { Provide } from '@midwayjs/decorator';
|
|
import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
-import { BaseService } from 'free-midway-component';
|
|
|
|
|
|
+import {
|
|
|
|
+ BaseService,
|
|
|
|
+ FrameworkErrorEnum,
|
|
|
|
+ ServiceError,
|
|
|
|
+} from 'free-midway-component';
|
|
import { Application } from '../entity/application.entity';
|
|
import { Application } from '../entity/application.entity';
|
|
|
|
+import { CDTO_application } from '../interface/application.interface';
|
|
|
|
+import { Match } from '../entity/match.entity';
|
|
|
|
+import { User } from '../entity/user.entity';
|
|
|
|
+import { Team } from '../entity/team.entity';
|
|
|
|
+const moment = require('moment');
|
|
type modelType = ReturnModelType<typeof Application>;
|
|
type modelType = ReturnModelType<typeof Application>;
|
|
@Provide()
|
|
@Provide()
|
|
export class ApplicationService extends BaseService<modelType> {
|
|
export class ApplicationService extends BaseService<modelType> {
|
|
@InjectEntityModel(Application)
|
|
@InjectEntityModel(Application)
|
|
model: modelType;
|
|
model: modelType;
|
|
|
|
+
|
|
|
|
+ @InjectEntityModel(Match)
|
|
|
|
+ MatchModel: ReturnModelType<typeof Match>;
|
|
|
|
+
|
|
|
|
+ @InjectEntityModel(User)
|
|
|
|
+ UserModel: ReturnModelType<typeof User>;
|
|
|
|
+
|
|
|
|
+ @InjectEntityModel(Team)
|
|
|
|
+ TeamModel: ReturnModelType<typeof Team>;
|
|
|
|
+ /**
|
|
|
|
+ * 检查是否有申请记录
|
|
|
|
+ * @param data 参数
|
|
|
|
+ */
|
|
|
|
+ async checkApply(data: CDTO_application) {
|
|
|
|
+ const res: any = await this.MatchModel.findById(data.match_id);
|
|
|
|
+ if (res) {
|
|
|
|
+ const flag = moment(moment().format('YYYY-MM-DD HH:mm:ss')).isBefore(
|
|
|
|
+ res.sign_deadline
|
|
|
|
+ );
|
|
|
|
+ if (!flag) {
|
|
|
|
+ throw new ServiceError(
|
|
|
|
+ '报名时间已过 无法报名!',
|
|
|
|
+ FrameworkErrorEnum.BAD_BODY
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (data.team_id) {
|
|
|
|
+ // 检查申请记录
|
|
|
|
+ const apply = await this.model.count({
|
|
|
|
+ match_id: data.match_id,
|
|
|
|
+ team_id: data.team_id,
|
|
|
|
+ });
|
|
|
|
+ if (apply > 0) {
|
|
|
|
+ throw new ServiceError(
|
|
|
|
+ '已有申请记录 请等待管理人员处理!',
|
|
|
|
+ FrameworkErrorEnum.BAD_BODY
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async specialQuery(filter) {
|
|
|
|
+ const { skip = 0, limit = 0, ...info } = filter;
|
|
|
|
+ if (info.user) {
|
|
|
|
+ const user = await this.UserModel.findById(info.user);
|
|
|
|
+ if (user.type === '0') {
|
|
|
|
+ info.user_id = { $elemMatch: { _id: info.user } };
|
|
|
|
+ delete info.user;
|
|
|
|
+ const list: any = await this.model.find(info).skip(skip).limit(limit);
|
|
|
|
+ const total = await this.model.count(info);
|
|
|
|
+ return { list, total };
|
|
|
|
+ } else if (user.type === '1') {
|
|
|
|
+ const list = [];
|
|
|
|
+ const user_id = info.user;
|
|
|
|
+ delete info.user;
|
|
|
|
+ const data: any = await this.model.find(info).skip(skip).limit(limit);
|
|
|
|
+ for (const val of data) {
|
|
|
|
+ const team = await this.TeamModel.findById(val.team_id);
|
|
|
|
+ if (team.administrator === user_id) list.push(val);
|
|
|
|
+ }
|
|
|
|
+ const total = list.length;
|
|
|
|
+ return { list, total };
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ const list: any = await this.model.find(info).skip(skip).limit(limit);
|
|
|
|
+ const total = await this.model.count(info);
|
|
|
|
+ return { list, total };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|