Class: RolesService
Defined in: packages/web-backend/src/roles/roles.service.ts:13
Service for roles persistence and predefined role initialization. Provides CRUD operations and bootstrap seeding.
Implements
OnApplicationBootstrap
Constructors
Constructor
new RolesService(
roleModel):RolesService
Defined in: packages/web-backend/src/roles/roles.service.ts:18
Construct the roles service with the injected Mongoose model.
Parameters
roleModel
Model<RolesDocument>
Mongoose model for the Roles collection
Returns
RolesService
Methods
createRole()
createRole(
role):Promise<void>
Defined in: packages/web-backend/src/roles/roles.service.ts:72
Create a single role from a RoleDTO object
Parameters
role
The RoleDTO object
Returns
Promise<void>
deleteRole()
deleteRole(
id):Promise<void>
Defined in: packages/web-backend/src/roles/roles.service.ts:96
Delete a role by its id or throw if it doesn't exist.
Parameters
id
string
The unique id of the role to delete
Returns
Promise<void>
getAllRoles()
getAllRoles(
roleId?):Promise<Roles[]>
Defined in: packages/web-backend/src/roles/roles.service.ts:42
This function returns all the roles from the database.
Parameters
roleId?
string[]
Optional list of role IDs to filter the results
Returns
Promise<Roles[]>
getRole()
getRole(
id):Promise<Roles>
Defined in: packages/web-backend/src/roles/roles.service.ts:60
Get a single role by Id or return NotFoundException if id doesnt exist
Parameters
id
string
The unique Id for the role
Returns
Promise<Roles>
onApplicationBootstrap()
onApplicationBootstrap():
void
Defined in: packages/web-backend/src/roles/roles.service.ts:28
This is a bootstrap function, called before routes are loaded by the application. This will load all the predefined roles defined in the predefiniedRoles.ts file. We can edit the predefinedRoles file to load even more predefined roles if required in the future
Returns
void
Implementation of
OnApplicationBootstrap.onApplicationBootstrap
updateRole()
updateRole(
role):Promise<void>
Defined in: packages/web-backend/src/roles/roles.service.ts:84
Update an existing role in the database
Parameters
role
The RoleDTO object
Returns
Promise<void>
