Class SecureRbacService

Service class responsible for handling Role-Based Access Control (RBAC) operations.

Hierarchy

  • SecureRbacService

Constructors

Properties

Methods

  • Parameters

    • assignPermissionToRoleDto: AssignPermissionToRoleDto

    Returns Promise<void>

  • Assigns a role to a user.

    Parameters

    Returns Promise<void>

    A promise that resolves when the role is assigned to the user successfully.

    Throws

    If the user or role with the specified ID is not found.

    Throws

    If the user already has the specified role.

  • Creates a new permission.

    Parameters

    • permissionDto: PermissionDto

      The data for creating the new permission.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

    A promise that resolves to the created Permission object.

    Throws

    If the permission with the same name already exists.

  • Creates a new role.

    Parameters

    • roleDto: RoleDto

      The data for creating the new role.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

    A promise that resolves to the created Role object.

    Throws

    If the role with the same name already exists.

  • Deactivate a Permission by its ID.

    Parameters

    • permissionId: number

      The ID of the role to delete.

    Returns Promise<void>

    A promise that resolves when the role is deleted successfully.

    Throws

    If the role with the specified ID is not found.

    Throws

    If the role has already been deleted.

  • Deletes a role by its ID.

    Parameters

    • roleId: number

      The ID of the role to delete.

    Returns Promise<void>

    A promise that resolves when the role is deleted successfully.

    Throws

    If the role with the specified ID is not found.

    Throws

    If the role has already been deleted.

  • Retrieves a permission by its ID.

    Parameters

    • id: number

      The ID of the permission to retrieve.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

    A promise that resolves to the Permission object with the given ID.

    Throws

    If the permission with the specified ID is not found.

  • Retrieves a list of all permissions.

    Returns Promise<(GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {})[]>

    A promise that resolves to an array of Permission objects.

  • Retrieves a list of permissions assigned to a user.

    Parameters

    • userId: number

      The ID of the user.

    Returns Promise<(GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {})[]>

    A promise that resolves to an array of Permission objects.

  • Retrieves a role by its ID.

    Parameters

    • roleId: number

      The ID of the role to retrieve.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

    A promise that resolves to the Role object with the given ID.

    Throws

    If the role with the specified ID is not found.

  • Retrieves a list of all roles.

    Returns Promise<(GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {})[]>

    A promise that resolves to an array of Role objects.

  • Checks if a user has specific permissions.

    Parameters

    • userId: number

      The ID of the user.

    • requiredPermissions: string[]

      An array of permission names required for access.

    Returns Promise<boolean>

    A promise that resolves to true if the user has all the required permissions; otherwise, false.

  • Checks if a user has specific roles.

    Parameters

    • userId: any

      The ID of the user.

    • requiredRoles: string[]

      An array of role names required for access.

    Returns Promise<boolean>

    A promise that resolves to true if the user has all the required roles; otherwise, false.

  • Removes permissions from a role based on the provided DTO.

    Parameters

    • removePermissionFromRoleDto: AssignPermissionToRoleDto

      The DTO containing roleId and permissionIds.

    Returns Promise<void>

    Async

    Throws

    If the role or permission is not found.

    Throws

    If a permission is not associated with the role.

  • Disconnects a role from a user based on the provided DTO.

    Parameters

    Returns Promise<void>

    Async

    Throws

    If the user or role is not found.

    Throws

    If the user doesn't have the specified role.

  • Updates a permission by its ID.

    Parameters

    • id: number

      The ID of the permission to update.

    • updatePermissionDto: PermissionDto

      The data for updating the permission.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

    A promise that resolves to the updated Permission object.

    Throws

    If the permission with the specified ID is not found.

  • Updates a role by its ID.

    Parameters

    • updatePermissionToRoleDto: AssignPermissionToRoleDto

      The data for updating the role.

    Returns Promise<void>

    Throws

    If the role with the specified ID is not found.

  • Parameters

    • roleId: number
    • updateRoleDto: RoleDto

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        id: number;
        name: string;
        updatedAt: Date;
    }, unknown> & {}>

Generated using TypeDoc