|
|
@@ -6,10 +6,9 @@ export class RoleServiceMt extends ConcreteCrudService<RoleMt> {
|
|
|
constructor(dataSource: DataSource) {
|
|
|
super(RoleMt, {
|
|
|
userTracking: {
|
|
|
- enabled: false
|
|
|
+ // 禁用用户追踪
|
|
|
},
|
|
|
tenantOptions: {
|
|
|
- enabled: true,
|
|
|
tenantIdField: 'tenantId',
|
|
|
autoExtractFromContext: true
|
|
|
}
|
|
|
@@ -41,7 +40,7 @@ export class RoleServiceMt extends ConcreteCrudService<RoleMt> {
|
|
|
*/
|
|
|
async hasPermission(roleId: number, permission: string, tenantId?: number): Promise<boolean> {
|
|
|
try {
|
|
|
- const role = await this.getById(roleId, [], { tenantId });
|
|
|
+ const role = await this.getById(roleId, [], tenantId);
|
|
|
if (!role) return false;
|
|
|
|
|
|
return role.permissions.includes(permission);
|
|
|
@@ -73,13 +72,13 @@ export class RoleServiceMt extends ConcreteCrudService<RoleMt> {
|
|
|
/**
|
|
|
* 根据ID获取角色(重写以添加租户过滤)
|
|
|
*/
|
|
|
- async getById(id: number, relations: string[] = [], options?: { tenantId?: number }): Promise<RoleMt | null> {
|
|
|
+ async getById(id: number, relations: string[] = [], userId?: string | number): Promise<RoleMt | null> {
|
|
|
try {
|
|
|
const where: any = { id };
|
|
|
|
|
|
- // 如果提供了租户ID,添加租户过滤
|
|
|
- if (options?.tenantId !== undefined) {
|
|
|
- where.tenantId = options.tenantId;
|
|
|
+ // 如果提供了租户ID(作为userId参数传递),添加租户过滤
|
|
|
+ if (userId !== undefined && typeof userId === 'number') {
|
|
|
+ where.tenantId = userId;
|
|
|
}
|
|
|
|
|
|
return await this.repository.findOne({ where, relations });
|
|
|
@@ -92,17 +91,17 @@ export class RoleServiceMt extends ConcreteCrudService<RoleMt> {
|
|
|
/**
|
|
|
* 更新角色(重写以添加租户过滤)
|
|
|
*/
|
|
|
- async update(id: number, data: Partial<RoleMt>, options?: { tenantId?: number }): Promise<RoleMt | null> {
|
|
|
+ async update(id: number, data: Partial<RoleMt>, userId?: string | number): Promise<RoleMt | null> {
|
|
|
try {
|
|
|
// 首先验证角色是否存在且属于指定租户
|
|
|
- const existingRole = await this.getById(id, [], options);
|
|
|
+ const existingRole = await this.getById(id, [], userId);
|
|
|
if (!existingRole) return null;
|
|
|
|
|
|
// 更新角色
|
|
|
await this.repository.update(id, data);
|
|
|
|
|
|
// 返回更新后的角色
|
|
|
- return await this.getById(id, [], options);
|
|
|
+ return await this.getById(id, [], userId);
|
|
|
} catch (error) {
|
|
|
console.error('Error updating role:', error);
|
|
|
throw new Error('Failed to update role');
|
|
|
@@ -112,10 +111,10 @@ export class RoleServiceMt extends ConcreteCrudService<RoleMt> {
|
|
|
/**
|
|
|
* 删除角色(重写以添加租户过滤)
|
|
|
*/
|
|
|
- async delete(id: number, options?: { tenantId?: number }): Promise<boolean> {
|
|
|
+ async delete(id: number, userId?: string | number): Promise<boolean> {
|
|
|
try {
|
|
|
// 首先验证角色是否存在且属于指定租户
|
|
|
- const existingRole = await this.getById(id, [], options);
|
|
|
+ const existingRole = await this.getById(id, [], userId);
|
|
|
if (!existingRole) return false;
|
|
|
|
|
|
// 删除角色
|