Browse Source

修改会审专家表

zs 2 years ago
parent
commit
297efb3f0b

+ 55 - 2
src/controller/achieveExpert.controller.ts

@@ -1,5 +1,6 @@
 import {
   Body,
+  Config,
   Controller,
   Del,
   Get,
@@ -8,7 +9,11 @@ import {
   Post,
   Query,
 } from '@midwayjs/decorator';
-import { BaseController } from 'free-midway-component';
+import {
+  BaseController,
+  FrameworkErrorEnum,
+  ServiceError,
+} from 'free-midway-component';
 import { AchieveExpertService } from '../service/achieveExpert.service';
 import {
   CDTO_achieveExpert,
@@ -18,15 +23,63 @@ import {
   QVO_achieveExpert,
   UDTO_achieveExpert,
   UVAO_achieveExpert,
+  LoginDTO,
+  ResetPasswordDTO,
+  LoginVO,
 } from '../interface/achieveExpert.interface';
-import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import {
+  ApiOperation,
+  ApiQuery,
+  ApiResponse,
+  ApiTags,
+} from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
+import { JwtService } from '@midwayjs/jwt';
+import get = require('lodash/get');
 @ApiTags(['会审专家表'])
 @Controller('/achieveExpert')
 export class AchieveExpertController extends BaseController {
   @Inject()
   service: AchieveExpertService;
 
+  @Inject()
+  jwtService: JwtService;
+
+  @Config('jwt.secret')
+  jwtSecret;
+
+  @Config('jwt.expiresIn')
+  jwtExpiresIn;
+
+  @Post('/login')
+  @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,
+    });
+    return token;
+  }
+
+  @Post('/rp')
+  @ApiOperation({ description: '修改密码' })
+  async resetPassword(@Body() body: ResetPasswordDTO) {
+    // 获取用户token中的登录信息
+    const user_id = get(this.ctx, 'user._id');
+    if (!user_id)
+      throw new ServiceError('未找到用户信息', FrameworkErrorEnum.NOT_LOGIN);
+    // 查询用户
+    const user = await this.service.fetch(user_id);
+    if (!user)
+      throw new ServiceError('未找到用户', FrameworkErrorEnum.NOT_FOUND_DATA);
+    // 修改密码
+    await this.service.updateOne(user_id, body);
+    // 返回结果
+    return 'ok';
+  }
+
   @Post('/')
   @Validate()
   @ApiResponse({ type: CVO_achieveExpert })

+ 1 - 1
src/entity/achieveExpert.entity.ts

@@ -14,7 +14,7 @@ export class AchieveExpert extends BaseModel {
   @prop({ required: false, index: true, zh: '专家姓名' })
   expert_name: string;
   @prop({ required: false, index: true, zh: '账号' })
-  acount: string;
+  account: string;
   @prop({
     required: false,
     index: false,

+ 55 - 4
src/interface/achieveExpert.interface.ts

@@ -23,7 +23,7 @@ export class FVO_achieveExpert {
   @ApiProperty({ description: '专家姓名' })
   'expert_name': string = undefined;
   @ApiProperty({ description: '账号' })
-  'acount': string = undefined;
+  'account': string = undefined;
   @ApiProperty({ description: '密码' })
   'password': string = undefined;
   @ApiProperty({ description: '手机号' })
@@ -54,7 +54,7 @@ export class QDTO_achieveExpert extends SearchBase {
       'role',
       'expert_id',
       'expert_name',
-      'acount',
+      'account',
       'phone',
       'company',
       'group_zw',
@@ -76,7 +76,7 @@ export class QDTO_achieveExpert extends SearchBase {
   @ApiProperty({ description: '专家姓名' })
   'expert_name': string = undefined;
   @ApiProperty({ description: '账号' })
-  'acount': string = undefined;
+  'account': string = undefined;
   @ApiProperty({ description: '手机号' })
   'phone': string = undefined;
   @ApiProperty({ description: '工作单位' })
@@ -117,7 +117,7 @@ export class CDTO_achieveExpert {
   'expert_name': string = undefined;
   @ApiProperty({ description: '账号' })
   @Rule(RuleType['string']().empty(''))
-  'acount': string = undefined;
+  'account': string = undefined;
   @ApiProperty({ description: '密码' })
   @Rule(RuleType['string']().empty(''))
   'password': string = undefined;
@@ -169,3 +169,54 @@ export class UVAO_achieveExpert extends FVO_achieveExpert {
     dealVO(this, data);
   }
 }
+
+export class LoginVO {
+  constructor(data: object) {
+    for (const key of Object.keys(this)) {
+      this[key] = get(data, key);
+    }
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
+  @ApiProperty({ description: '专家id' })
+  'expert_id': string = undefined;
+  @ApiProperty({ description: '专家姓名' })
+  'expert_name': string = undefined;
+  @ApiProperty({ description: '账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '手机号' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '工作单位' })
+  'company': string = undefined;
+  @ApiProperty({ description: '评价专家组职务' })
+  'group_zw': string = undefined;
+  @ApiProperty({ description: '所学专业' })
+  'major': string = undefined;
+  @ApiProperty({ description: '现从事专业' })
+  'on_major': string = undefined;
+  @ApiProperty({ description: '职务' })
+  'zw': string = undefined;
+  @ApiProperty({ description: '职称' })
+  'zc': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class LoginDTO {
+  @ApiProperty({ description: '账号', example: 'test' })
+  @Rule(RuleType['string']().empty(''))
+  'account': string = undefined;
+  @ApiProperty({ description: '密码', example: '111111' })
+  @Rule(RuleType['string']().empty(''))
+  'password': string = undefined;
+}
+
+export class ResetPasswordDTO {
+  @ApiProperty({ description: '密码', example: '123456' })
+  @Rule(RuleType['string']().required())
+  'password': string = undefined;
+}

+ 20 - 1
src/service/achieveExpert.service.ts

@@ -1,11 +1,30 @@
 import { Provide } from '@midwayjs/decorator';
 import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
-import { BaseService } from 'free-midway-component';
+import {
+  BaseService,
+  FrameworkErrorEnum,
+  ServiceError,
+} from 'free-midway-component';
 import { AchieveExpert } from '../entity/achieveExpert.entity';
+import { LoginDTO } from '../interface/achieveExpert.interface';
+import isEqual = require('lodash/isEqual');
 type modelType = ReturnModelType<typeof AchieveExpert>;
 @Provide()
 export class AchieveExpertService extends BaseService<modelType> {
   @InjectEntityModel(AchieveExpert)
   model: modelType;
+
+  async findUserToLogin(data: LoginDTO): Promise<object> {
+    const { account, password } = data;
+    const user = await this.model.findOne({ account }, '+password').lean();
+    if (!user)
+      throw new ServiceError(
+        '未找到会审专家信息',
+        FrameworkErrorEnum.NOT_FOUND_DATA
+      );
+    if (!isEqual(user.password.secret, password))
+      throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
+    return user;
+  }
 }