zs 1 year ago
parent
commit
8dede6b569

+ 1 - 1
src/config/config.local.ts

@@ -47,7 +47,7 @@ export default {
     // 羽毛球比赛
     friendShoolApp: {
       appid: 'wx23c71bee5876d1b9',
-      secret: '5bd08ecf8113b3fa6d34a4772c14758d',
+      secret: '8d2a8f0ba07b2d4728409971f4c71f7b',
       mchid: '1505364491',
       v3key: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9',
     },

+ 1 - 1
src/config/config.prod.ts

@@ -47,7 +47,7 @@ export default {
     // 羽毛球比赛
     friendShoolApp: {
       appid: 'wx23c71bee5876d1b9',
-      secret: '5bd08ecf8113b3fa6d34a4772c14758d',
+      secret: '8d2a8f0ba07b2d4728409971f4c71f7b',
       mchid: '1505364491',
       v3key: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9',
     },

+ 9 - 5
src/controller/user.controller.ts

@@ -34,6 +34,7 @@ import {
   ApiTags,
 } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
+import { UserUtilService } from '../service/util/user.util';
 import { JwtService } from '@midwayjs/jwt';
 @ApiTags(['用户'])
 @Controller('/user')
@@ -44,6 +45,9 @@ export class UserController extends BaseController {
   @Inject()
   jwtService: JwtService;
 
+  @Inject()
+  userUtil: UserUtilService;
+
   @Config('jwt.secret')
   jwtSecret;
 
@@ -54,11 +58,7 @@ export class UserController extends BaseController {
   @Validate()
   async login(@Body() body: LoginDTO) {
     const data = await this.service.findUserToLogin(body);
-    let vo = new LoginVO(data);
-    vo = JSON.parse(JSON.stringify(vo));
-    const token = await this.jwtService.sign(vo, this.jwtSecret, {
-      expiresIn: this.jwtExpiresIn,
-    });
+    const token = new LoginVO(data);
     return token;
   }
 
@@ -81,6 +81,8 @@ export class UserController extends BaseController {
   @Validate()
   @ApiResponse({ type: CVO_user })
   async create(@Body() data: CDTO_user) {
+    // 检查账号
+    await this.userUtil.checkPhoneAndPid(data);
     const dbData = await this.service.create(data);
     const result = new CVO_user(dbData);
     return result;
@@ -115,6 +117,8 @@ export class UserController extends BaseController {
   @Validate()
   @ApiResponse({ type: UVAO_user })
   async update(@Param('id') id: string, @Body() body: UDTO_user) {
+    // 检查账号
+    await this.userUtil.checkUpdateCardAndPid(id, body);
     const result = await this.service.updateOne(id, body);
     return result;
   }

+ 6 - 0
src/interface/util/user.util.interface.ts

@@ -0,0 +1,6 @@
+export interface CheckUpdateCardAndPid {
+  account?: string;
+}
+export interface checkPhoneAndPid {
+  account?: string;
+}

+ 53 - 0
src/service/util/user.util.ts

@@ -0,0 +1,53 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { User } from '../../entity/user.entity';
+import {
+  CheckUpdateCardAndPid,
+  checkPhoneAndPid,
+} from '../../interface/util/user.util.interface';
+
+@Provide()
+export class UserUtilService {
+  @InjectEntityModel(User)
+  userModel: ReturnModelType<typeof User>;
+
+  /**
+   * 检查创建时,账号
+   * @param data 参数
+   */
+  async checkPhoneAndPid(data: checkPhoneAndPid) {
+    if (data.account) {
+      // 检查账号
+      // 管理员
+      const useran = await this.userModel.count({ account: data.account });
+      if (useran > 0) {
+        throw new ServiceError(
+          '已有用户 使用该账号',
+          FrameworkErrorEnum.BAD_BODY
+        );
+      }
+    }
+  }
+  /**
+   * 检查创建时,账号
+   * @param id 当前要修改的数据
+   * @param data 参数
+   */
+  async checkUpdateCardAndPid(id, data: CheckUpdateCardAndPid) {
+    const { account } = data;
+    if (account) {
+      // 用户
+      const personalan = await this.userModel.count({
+        _id: { $ne: id },
+        account,
+      });
+      if (personalan > 0)
+        throw new ServiceError(
+          `账号: ${account} ;已有个人用户使用该账号`,
+          FrameworkErrorEnum.BAD_BODY
+        );
+    }
+  }
+}