From d96f18e6cf97df2ce6f55cce7138cdfd8cd13ce3 Mon Sep 17 00:00:00 2001 From: Jackson Roberts Date: Sun, 25 Jan 2026 15:09:55 -0600 Subject: [PATCH] Fixed UserController errors --- src/controllers/RoleController.ts | 10 +++++----- src/controllers/UserController.ts | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/controllers/RoleController.ts b/src/controllers/RoleController.ts index f52c1c0..8d20752 100644 --- a/src/controllers/RoleController.ts +++ b/src/controllers/RoleController.ts @@ -78,7 +78,7 @@ export class RoleController { }); throw new PermissionsVerificationError( `Unable to verify permissions for role '${this.title}, it is recommended that you override and rewrite these permissions immediately.`, - (err as Error).message + (err as Error).message, ); } @@ -248,14 +248,14 @@ export class RoleController { title: string; moniker: string; permissions: string[]; - }> + }>, ) { const schema = z .object({ title: z.string().min(1, "Title cannot be empty."), moniker: z.string().min(1, "Moniker cannot be empty."), permissions: z.array( - z.string().min(1, "Permission node cannot be empty") + z.string().min(1, "Permission node cannot be empty"), ), }) .partial() @@ -271,7 +271,7 @@ export class RoleController { if (checkMoniker) throw new RoleError( "Moniker is already taken.", - "Another role with this moniker already exists in the databse." + "Another role with this moniker already exists in the databse.", ); } @@ -326,7 +326,7 @@ export class RoleController { id: v.id, name: v.name, login: v.login, - roles: v.roles.map((r:any) => r.id), + roles: v.roles.map((r: any) => r.id), })) : undefined, createdAt: this.createdAt, diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 93a9a12..683c79c 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -141,16 +141,22 @@ export default class UserController { }, }); - const implicitPermissions = Object.keys(resources ?? {}) - .filter((v) => resources![v].length > 0) - .map( - (v) => - `resource.${v}.[${(resources![v] as { id: string }[]) - .map((o) => o.id) - .join(",")}].user.${this.id}.implicit`, - ); + const resourceKeys: string[] = Object.keys(resources ?? {}) as string[]; - console.log(implicitPermissions); + const implicitPermissions = resources + ? resourceKeys + // @ts-ignore + .filter((v) => resources[v].length > 0) + .map( + (v) => + //@ts-ignore + `resource.${v}.[${(resources![v] as { id: string }[]) + .map((o) => o.id) + .join(",")}].user.${this.id}.implicit`, + ) + : []; + + // console.log(implicitPermissions); let checks = [ (await this.fetchRoles()).map((v) => v.checkPermission(permission)),