11import { HttpException , HttpStatus , Injectable } from '@nestjs/common' ;
22import { ConfigService } from '@nestjs/config' ;
33import { InjectRepository } from '@nestjs/typeorm' ;
4+ import { ResourcesTypeEnum } from '@src/enums/resources.type.enum' ;
45import { LoggerService } from '@src/plugin/logger/logger.service' ;
56import { RedisService } from '@src/plugin/redis/redis.service' ;
67import { ToolsService } from '@src/plugin/tools/tools.service' ;
7- import { Repository , SelectQueryBuilder } from 'typeorm' ;
8+ import { In , Repository , SelectQueryBuilder } from 'typeorm' ;
89import { AccountEntity } from '../account/entities/account.entity' ;
10+ import { AccountRoleEntity } from '../accountRole/entities/account.role.entity' ;
11+ import { ResourcesEntity } from '../resources/entities/resources.entity' ;
12+ import { RoleResourcesEntity } from '../roleResources/entities/role.resources.entity' ;
913import { LoginDto } from './dto/login.dto' ;
1014import { LoginAccountVo , LoginTokenDataVo , LoginVo } from './vo/login.vo' ;
1115
@@ -14,6 +18,12 @@ export class LoginService {
1418 constructor (
1519 @InjectRepository ( AccountEntity )
1620 private readonly accountRepository : Repository < AccountEntity > ,
21+ @InjectRepository ( AccountRoleEntity )
22+ private readonly accountRoleRepository : Repository < AccountRoleEntity > ,
23+ @InjectRepository ( RoleResourcesEntity )
24+ private readonly roleResourcesRepository : Repository < RoleResourcesEntity > ,
25+ @InjectRepository ( ResourcesEntity )
26+ private readonly resourcesRepository : Repository < ResourcesEntity > ,
1727 private readonly toolsService : ToolsService ,
1828 private readonly loggerService : LoggerService ,
1929 private readonly redisService : RedisService ,
@@ -106,9 +116,39 @@ export class LoginService {
106116 const token = this . toolsService . uuidToken ;
107117 const refreshToken = this . toolsService . uuidToken ;
108118 const sign = this . toolsService . uuidToken ;
119+ // 根据当前用户获取授权的按钮权限
120+ const accountRoleEntityList : Pick < AccountRoleEntity , 'roleId' > [ ] =
121+ await this . accountRoleRepository . find ( {
122+ where : {
123+ accountId : accountEntity . id ,
124+ } ,
125+ select : [ 'roleId' ] ,
126+ } ) ;
127+ const roleIdList = accountRoleEntityList . map ( ( item ) => item . roleId ) ;
128+ const roleResourcesList : Pick < RoleResourcesEntity , 'resourcesId' > [ ] =
129+ await this . roleResourcesRepository . find ( {
130+ where : {
131+ type : 1 ,
132+ roleId : In ( roleIdList ) ,
133+ } ,
134+ select : [ 'resourcesId' ] ,
135+ } ) ;
136+ const resourcesIdList = roleResourcesList . map ( ( item ) => item . resourcesId ) ;
137+ // 查询全部的资源
138+ const resourcesEntity = await this . resourcesRepository . find ( {
139+ where : {
140+ id : In ( resourcesIdList ) ,
141+ } ,
142+ select : [ 'url' , 'method' , 'title' , 'resourcesType' ] ,
143+ } ) ;
144+ console . log ( resourcesEntity , '1111' ) ;
145+ const resources = resourcesEntity . filter ( ( item ) => item . resourcesType == ResourcesTypeEnum . API ) ;
146+ console . log ( resources , '全部的资源' ) ;
147+ // 根据角色idList去查询授权的按钮
109148 // 根据资源id获取资源信息
110149 const redisData : LoginTokenDataVo = {
111150 userInfo : accountEntity , // 用户信息
151+ authApi : resources , // 授权的api接口
112152 sign,
113153 } ;
114154 // 正常token
0 commit comments