Browse Source

修改接口

zs 1 year ago
parent
commit
3a770e9164

+ 8 - 0
src/controller/Role.controller.ts

@@ -53,6 +53,14 @@ export class RoleController extends BaseController {
     return { data, total };
   }
 
+  @Get('/menu')
+  @ApiResponse({ type: FVO_Role })
+  async menu(@Query('is_use') is_use: string, @Query('code') code: string) {
+    const data = await this.service.menu(is_use, code);
+    const result = new FVO_Role(data);
+    return result;
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_Role })
   async fetch(@Param('id') id: string) {

+ 12 - 0
src/controller/User.controller.ts

@@ -109,6 +109,18 @@ export class UserController extends BaseController {
     return { data, total };
   }
 
+  @Get('/openid')
+  @ApiResponse({ type: FVO_User })
+  async wxLogin(@Query('openid') openid: string) {
+    const data = await this.service.wxLogin(openid);
+    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;
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_User })
   async fetch(@Param('id') id: string) {

+ 0 - 2
src/entity/User.entity.ts

@@ -5,8 +5,6 @@ import isString = require('lodash/isString');
   schemaOptions: { collection: 'User' },
 })
 export class User extends BaseModel {
-  @prop({ required: false, index: false, zh: '头像' })
-  icon: Array<any>;
   @prop({ required: true, index: true, zh: '姓名' })
   name: string;
   @prop({ required: true, index: true, zh: '联系电话' })

+ 0 - 7
src/interface/User.interface.ts

@@ -18,8 +18,6 @@ export class FVO_User {
   }
   @ApiProperty({ description: '数据id' })
   _id: string = undefined;
-  @ApiProperty({ description: '头像' })
-  'icon': Array<any> = undefined;
   @ApiProperty({ description: '姓名' })
   'name': string = undefined;
   @ApiProperty({ description: '联系电话' })
@@ -79,9 +77,6 @@ export class QVO_User extends FVO_User {
 }
 
 export class CDTO_User {
-  @ApiProperty({ description: '头像' })
-  @Rule(RuleType['array']().empty(''))
-  'icon': Array<any> = undefined;
   @ApiProperty({ description: '姓名' })
   @Rule(
     RuleType['string']()
@@ -163,8 +158,6 @@ export class LoginVO {
   }
   @ApiProperty({ description: '数据id' })
   _id: string = undefined;
-  @ApiProperty({ description: '头像' })
-  'icon': Array<any> = undefined;
   @ApiProperty({ description: '姓名' })
   'name': string = undefined;
   @ApiProperty({ description: '联系电话' })

+ 15 - 1
src/service/Role.service.ts

@@ -1,11 +1,25 @@
 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 { Role } from '../entity/Role.entity';
 type modelType = ReturnModelType<typeof Role>;
 @Provide()
 export class RoleService extends BaseService<modelType> {
   @InjectEntityModel(Role)
   model: modelType;
+
+  async menu(is_use: string, code: string): Promise<object> {
+    const menu = await this.model.findOne({ is_use, code }).lean();
+    if (!menu)
+      throw new ServiceError(
+        '未找到菜单信息',
+        FrameworkErrorEnum.NOT_FOUND_DATA
+      );
+    return menu;
+  }
 }

+ 9 - 0
src/service/user.service.ts

@@ -29,4 +29,13 @@ export class UserService extends BaseService<modelType> {
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
+  async wxLogin(openid: any): Promise<object> {
+    const user = await this.model.findOne({ openid, status: '1' }).lean();
+    if (!user)
+      throw new ServiceError(
+        '未找到用户信息',
+        FrameworkErrorEnum.NOT_FOUND_DATA
+      );
+    return user;
+  }
 }