|
@@ -2,11 +2,13 @@ import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayj
|
|
|
import { BaseController } from '../../frame/BaseController';
|
|
|
import { ApiQuery, ApiResponse, ApiTags } from '@midwayjs/swagger';
|
|
|
import { Validate } from '@midwayjs/validate';
|
|
|
-import { omit, pick } from 'lodash';
|
|
|
+import { get, omit, pick } from 'lodash';
|
|
|
import { ErrorCode, ServiceError } from '../../error/service.error';
|
|
|
import { UserService } from '../../service/system/user.service';
|
|
|
import { CVO_user, FVO_user, QVO_user, UVAO_user } from '../../interface/system/user.interface';
|
|
|
import { RoleService } from '../../service/system/role.service';
|
|
|
+import * as bcrypt from 'bcryptjs';
|
|
|
+
|
|
|
const namePrefix = '平台用户';
|
|
|
@ApiTags(['平台用户'])
|
|
|
@Controller('/user', { tagName: namePrefix })
|
|
@@ -65,6 +67,13 @@ export class UserController implements BaseController {
|
|
|
await this.service.createExamine(data);
|
|
|
await this.service.checkPhone(data);
|
|
|
await this.service.checkEmail(data);
|
|
|
+
|
|
|
+ const passowrd = get(data, 'password');
|
|
|
+ if (passowrd) {
|
|
|
+ const salt = bcrypt.genSaltSync(10);
|
|
|
+ const hash = bcrypt.hashSync(passowrd, salt);
|
|
|
+ Object.assign(data, { password: hash });
|
|
|
+ }
|
|
|
const dbData = await this.service.create(data);
|
|
|
const result = new CVO_user(dbData);
|
|
|
return result;
|
|
@@ -76,8 +85,9 @@ export class UserController implements BaseController {
|
|
|
@ApiResponse({ type: UVAO_user })
|
|
|
async update(@Param('id') id: number, @Body() data: object) {
|
|
|
if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
|
|
|
- await this.service.checkPhone(data)
|
|
|
- await this.service.checkEmail(data)
|
|
|
+ await this.service.checkPhone(data);
|
|
|
+ await this.service.checkEmail(data);
|
|
|
+ data = omit(data, ['password']);
|
|
|
const result = await this.service.update({ id }, data);
|
|
|
return result;
|
|
|
}
|