瀏覽代碼

修改报名权限

zs 1 年之前
父節點
當前提交
989b7c16a5

+ 1 - 0
src/controller/platform/sign.controller.ts

@@ -14,6 +14,7 @@ export class SignController extends BaseController {
   @Validate()
   @ApiResponse({ type: CVO_sign })
   async create(@Body() data: CDTO_sign) {
+    await this.service.createExamine(data);
     const dbData = await this.service.create(data);
     const result = new CVO_sign(dbData);
     return result;

+ 1 - 0
src/error/frame.error.ts

@@ -11,5 +11,6 @@ export enum ErrorCode {
   ACCOUNT_LOGGED_IN_ELESWHERE = '401-5',
   USER_IS_DISABLED = '401-6',
   ROLE_IS_DISABLED = '401-7',
+  SERVICE_REPEAT = '401-8',
 }
 export const FrameErrorEnum = registerErrorCode('FrameError', ErrorCode);

+ 1 - 0
src/locales/zh_cn/errors.ts

@@ -23,6 +23,7 @@ const codes = {
   '401-5': '本账号已在其他地方登录,请重新登录!',
   '401-6': '该用户已被禁用',
   '401-7': '当前角色下的用户无法使用',
+  '401-8': '该比赛已报名请勿重复报名!',
 };
 const errCodes = {};
 const prefix = 'FRAMEERROR_';

+ 14 - 1
src/service/platform/sign.service.ts

@@ -1,10 +1,13 @@
-import { Provide } from '@midwayjs/decorator';
+import { Provide, Inject } from '@midwayjs/decorator';
+import { ServiceError } from 'free-midway-component';
 import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Sign } from '../../entity/platform/sign.entity';
 import { Match } from '../../entity/platform/match.entity';
 import { get } from 'lodash';
+import { I18nService } from '../i18n.service';
+import { FrameErrorEnum } from '../../error/frame.error';
 type modelType = ReturnModelType<typeof Sign>;
 @Provide()
 export class SignService extends BaseService<modelType> {
@@ -14,6 +17,16 @@ export class SignService extends BaseService<modelType> {
   @InjectEntityModel(Match)
   mModel: ReturnModelType<typeof Match>;
 
+  @Inject()
+  i18n: I18nService;
+
+  // 报名检查
+  async createExamine(data) {
+    const { user, match } = data;
+    const result = await this.model.findOne({ user, match }).lean();
+    if (result) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.SERVICE_REPEAT), FrameErrorEnum.SERVICE_REPEAT);
+  }
+
   // 列表
   async sign(query) {
     const { skip = 0, limit = 0, ...condition } = query;