ff-admin-server/src/service/management/roleService.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../data-source";
2025-02-15 10:59:54 +01:00
import { role } from "../../entity/management/role";
2025-01-29 09:42:22 +01:00
import DatabaseActionException from "../../exceptions/databaseActionException";
2025-01-05 14:14:00 +01:00
import InternalException from "../../exceptions/internalException";
2024-08-27 17:54:59 +02:00
export default abstract class RoleService {
2024-08-28 20:41:16 +02:00
/**
* @description get roles
* @returns {Promise<Array<role>>}
*/
static async getAll(): Promise<Array<role>> {
return await dataSource
.getRepository(role)
.createQueryBuilder("role")
2024-09-01 14:55:05 +02:00
.leftJoinAndSelect("role.permissions", "role_permissions")
2025-01-12 18:17:54 +01:00
.orderBy("role", "ASC")
2024-08-28 20:41:16 +02:00
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "roles", err);
2024-08-28 20:41:16 +02:00
});
}
2024-08-27 17:54:59 +02:00
/**
* @description get role by id
* @param id number
* @returns {Promise<role>}
*/
static async getById(id: number): Promise<role> {
return await dataSource
.getRepository(role)
.createQueryBuilder("role")
2024-09-01 14:55:05 +02:00
.leftJoinAndSelect("role.permissions", "role_permissions")
2024-08-27 17:54:59 +02:00
.where("role.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "role", err);
2024-08-27 17:54:59 +02:00
});
}
}