🎏 refactor: Streamline Role Permissions from Interface Config

This commit is contained in:
Danny Avila 2025-08-14 02:15:33 -04:00
parent b742c8c7f9
commit e8ddd279fd
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
5 changed files with 1008 additions and 231 deletions

View file

@ -15,14 +15,12 @@ export function createRoleMethods(mongoose: typeof import('mongoose')) {
const defaultPerms = roleDefaults[roleName].permissions;
if (!role) {
// Create new role if it doesn't exist.
role = new Role(roleDefaults[roleName]);
} else {
// Ensure role.permissions is defined.
const permissions = role.toObject()?.permissions ?? {};
role.permissions = role.permissions || {};
// For each permission type in defaults, add it if missing.
for (const permType of Object.keys(defaultPerms)) {
if (role.permissions[permType] == null) {
if (permissions[permType] == null || Object.keys(permissions[permType]).length === 0) {
role.permissions[permType] = defaultPerms[permType as keyof typeof defaultPerms];
}
}