Skip to content

Commit c06aa98

Browse files
committed
feat: 修复bug
1 parent e543b38 commit c06aa98

File tree

7 files changed

+44
-36
lines changed

7 files changed

+44
-36
lines changed

src/api/account/account.service.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ export class AccountService {
171171
const {
172172
status,
173173
username,
174-
tenantId: queryTenantId,
175174
pageNumber = PageEnum.PAGE_NUMBER,
176175
pageSize = PageEnum.PAGE_SIZE,
177176
} = queryOption;
@@ -182,31 +181,32 @@ export class AccountService {
182181
if ([StatusEnum.NORMAL, StatusEnum.FORBIDDEN].includes(status)) {
183182
query.set('status', Equal(status + ''));
184183
}
185-
const { accountType, id, tenantId } = currentInfo;
184+
const { id } = currentInfo;
186185
/**
187186
* 1.如果是超管,查询到全部的账号
188187
* 2.如果不是超管,是主账号的时候查询下面全部的账号
189188
* 3.如果都不是,只能查询账号下的数据
190189
*/
191-
if (queryTenantId) {
192-
query.set('tenantId', Equal(queryTenantId + ''));
193-
} else {
194-
if (accountType == AccountTypeEnum.SUPER_ACCOUNT) {
195-
console.log('超管不需要');
196-
} else if (accountType == AccountTypeEnum.PRIMARY_ACCOUNT) {
197-
query.set('tenantId', Equal(tenantId + ''));
198-
} else if (accountType == AccountTypeEnum.NORMAL_ACCOUNT) {
199-
query.set('parentId', Equal(id + ''));
200-
}
201-
}
190+
// if (queryTenantId) {
191+
// query.set('tenantId', Equal(queryTenantId + ''));
192+
// } else {
193+
// if (accountType == AccountTypeEnum.SUPER_ACCOUNT) {
194+
// console.log('超管不需要');
195+
// } else if (accountType == AccountTypeEnum.PRIMARY_ACCOUNT) {
196+
// query.set('tenantId', Equal(tenantId + ''));
197+
// } else if (accountType == AccountTypeEnum.NORMAL_ACCOUNT) {
198+
// query.set('parentId', Equal(id + ''));
199+
// }
200+
// }
201+
query.set('parentId', Equal(id + ''));
202202

203203
const total = await this.accountRepository
204204
.createQueryBuilder('account')
205-
.where(mapToObj(query))
205+
.where([mapToObj(query), { id: id }])
206206
.getCount();
207207
const queryBuilder = this.queryAccountBuilder;
208208
const data = await queryBuilder
209-
.where(mapToObj(query))
209+
.where([mapToObj(query), { id: id }])
210210
.orderBy({ accountType: 'DESC', id: 'DESC' })
211211
.offset((pageNumber - 1) * pageSize)
212212
.limit(pageSize)

src/api/accountRole/accountRole.controller.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Controller, Get, Post, Body, Param, ParseIntPipe, Query, UseGuards } from '@nestjs/common';
2+
import { CurrentUser, ICurrentUserType } from '@src/decorators';
23
import { AuthGuard } from '@src/guard/auth.guard';
34
import { RoleEntity } from '../role/entities/role.entity';
45
import { AccountRoleService } from './accountRole.service';
@@ -22,7 +23,10 @@ export class AccountRoleController {
2223
}
2324

2425
@Get()
25-
async getAllRolesApi(@Query('status') status: number): Promise<RoleEntity[]> {
26-
return await this.accountRoleService.getAllRolesApi(status);
26+
async getAllRolesApi(
27+
@Query('status') status: number,
28+
@CurrentUser('userInfo') currentInfo: ICurrentUserType
29+
): Promise<RoleEntity[]> {
30+
return await this.accountRoleService.getAllRolesApi(status, currentInfo);
2731
}
2832
}

src/api/accountRole/accountRole.service.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RoleEntity } from '../role/entities/role.entity';
77
import { AccountRoleDto } from './dto/account.role.dto';
88
import { StatusEnum } from '@src/enums';
99
import { getC, getJ } from '@src/utils';
10+
import { ICurrentUserType } from '@src/decorators';
1011

1112
@Injectable()
1213
export class AccountRoleService {
@@ -138,13 +139,14 @@ export class AccountRoleService {
138139
* @LastEditors: 水痕
139140
* @Description: 获取全部角色
140141
* @param {number} status
142+
* @param {ICurrentUserType} currentInfo
141143
* @return {*}
142144
*/
143-
async getAllRolesApi(status: number): Promise<RoleEntity[]> {
145+
async getAllRolesApi(status: number, currentInfo: ICurrentUserType): Promise<RoleEntity[]> {
144146
if ([StatusEnum.NORMAL, StatusEnum.FORBIDDEN].includes(+status)) {
145-
return this.roleRepository.find({ where: { status } });
147+
return this.roleRepository.find({ where: { status, accountId: currentInfo.id } });
146148
} else {
147-
return this.roleRepository.find();
149+
return this.roleRepository.find({ where: { accountId: currentInfo.id } });
148150
}
149151
}
150152
}

src/api/menus/menus.repository.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
33
import { ICurrentUserType } from '@src/decorators';
44
import { AccountTypeEnum } from '@src/enums/account.type.enum';
55
import { mapToObj } from '@src/utils';
6-
import { Repository, FindOperator, In } from 'typeorm';
6+
import { Repository, FindOperator, In, Equal } from 'typeorm';
77
import { AccountRoleEntity } from '../accountRole/entities/account.role.entity';
88
import { ResourcesEntity } from '../resources/entities/resources.entity';
99
import { RoleResourcesEntity } from '../roleResources/entities/role.resources.entity';
@@ -25,9 +25,10 @@ export class MenusRepository {
2525
* @LastEditors:
2626
* @Description: 内部使用,根据当前用户获取授权的资源id
2727
* @param {ICurrentUserType} userInfo
28+
* @param {number} type 类型,0表示菜单1表示按钮
2829
* @return {*}
2930
*/
30-
async getResourcesIdList(userInfo: ICurrentUserType): Promise<number[]> {
31+
async getResourcesIdList(userInfo: ICurrentUserType, type: number): Promise<number[]> {
3132
const { accountType } = userInfo;
3233
if (accountType == AccountTypeEnum.SUPER_ACCOUNT) {
3334
const resourcesEntity: Pick<ResourcesEntity, 'id'>[] = await this.resourcesRepository.find({
@@ -45,7 +46,9 @@ export class MenusRepository {
4546
if (!accountRoleEntity.length) {
4647
return [];
4748
}
49+
console.log('全部的角色', accountRoleEntity);
4850
query.set('roleId', In(accountRoleEntity.map((item) => item.roleId)));
51+
query.set('type', Equal(type + ''));
4952
// 2.根据角色查询授权的资源
5053
const roleResourcesEntity: Pick<RoleResourcesEntity, 'resourcesId'>[] =
5154
await this.roleResourcesRepository.find({

src/api/menus/menus.service.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class MenusService {
3232
query.set('resourcesType', In([0, 1]));
3333
// 如果是不是超级管理员就返回角色下的资源
3434
if (accountType !== AccountTypeEnum.SUPER_ACCOUNT) {
35-
const resourcesIdList = await this.menusRepository.getResourcesIdList(userInfo);
35+
const resourcesIdList = await this.menusRepository.getResourcesIdList(userInfo, 0);
3636
console.log(resourcesIdList, '资源');
3737
query.set('id', In(resourcesIdList));
3838
}
@@ -59,12 +59,11 @@ export class MenusService {
5959
where: { url: urlName },
6060
select: ['id'],
6161
});
62-
console.log(resourcesEntity, '????');
6362
if (!resourcesEntity?.id) {
6463
return [];
6564
}
6665
// 获取授权的资源id
67-
const resourcesId = await this.menusRepository.getResourcesIdList(userInfo);
66+
const resourcesId = await this.menusRepository.getResourcesIdList(userInfo, 1);
6867
console.log(resourcesId, '全部资源');
6968
return await this.resourcesRepository.find({
7069
where: {
@@ -87,7 +86,7 @@ export class MenusService {
8786
* @return {*}
8887
*/
8988
async getResourcesList(userInfo: ICurrentUserType): Promise<ResourcesEntity[]> {
90-
const resourcesId = await this.menusRepository.getResourcesIdList(userInfo);
89+
const resourcesId = await this.menusRepository.getResourcesIdList(userInfo, 0);
9190
return await this.resourcesRepository.find({
9291
where: { id: In(resourcesId) },
9392
});

src/api/resources/resources.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class ResourcesService {
175175
} else if (type == 1) {
176176
resourcesType = [0, 1, 2];
177177
}
178-
const resourcesIdList = await this.menusRepository.getResourcesIdList(currentInfo);
178+
const resourcesIdList = await this.menusRepository.getResourcesIdList(currentInfo, type);
179179
return await this.resourcesRepository.find({
180180
where: {
181181
id: In(resourcesIdList),

src/api/role/role.service.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { QueryRoleDto } from './dto/role.query';
1111
import { mapToObj } from '@src/utils';
1212
import { AccountEntity } from '../account/entities/account.entity';
1313
import { TenantEntity } from '../tenant/entities/tenant.entity';
14-
import { AccountTypeEnum } from '@src/enums/account.type.enum';
1514

1615
@Injectable()
1716
export class RoleService {
@@ -137,21 +136,22 @@ export class RoleService {
137136
pageNumber = PageEnum.PAGE_NUMBER,
138137
pageSize = PageEnum.PAGE_SIZE,
139138
} = queryOption;
140-
const { accountType, id, tenantId } = currentInfo;
139+
const { id } = currentInfo;
141140
const query = new Map<string, FindOperator<string>>();
142141
if (name) {
143142
query.set('name', ILike(`%${name}%`));
144143
}
145144
if (status >= 0) {
146145
query.set('status', Equal(status + ''));
147146
}
148-
if (accountType == AccountTypeEnum.SUPER_ACCOUNT) {
149-
console.log('超管');
150-
} else if (accountType == AccountTypeEnum.PRIMARY_ACCOUNT) {
151-
query.set('tenantId', Equal(tenantId + ''));
152-
} else if (accountType == AccountTypeEnum.NORMAL_ACCOUNT) {
153-
query.set('accountId', Equal(id + ''));
154-
}
147+
query.set('accountId', Equal(id + ''));
148+
// if (accountType == AccountTypeEnum.SUPER_ACCOUNT) {
149+
// console.log('超管');
150+
// } else if (accountType == AccountTypeEnum.PRIMARY_ACCOUNT) {
151+
// query.set('tenantId', Equal(tenantId + ''));
152+
// } else if (accountType == AccountTypeEnum.NORMAL_ACCOUNT) {
153+
// query.set('accountId', Equal(id + ''));
154+
// }
155155
const queryBuilder = this.queryRoleBuilder;
156156
const data = await queryBuilder
157157
.where(mapToObj(query))

0 commit comments

Comments
 (0)