folder structure

This commit is contained in:
Julian Krauser 2025-01-05 14:14:00 +01:00
parent 5d3f8ea46a
commit 84e2ec72ac
242 changed files with 635 additions and 635 deletions

View file

@ -0,0 +1,43 @@
import { dataSource } from "../../data-source";
import { role } from "../../entity/user/role";
import InternalException from "../../exceptions/internalException";
export default abstract class RoleService {
/**
* @description get roles
* @returns {Promise<Array<role>>}
*/
static async getAll(): Promise<Array<role>> {
return await dataSource
.getRepository(role)
.createQueryBuilder("role")
.leftJoinAndSelect("role.permissions", "role_permissions")
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("roles not found", err);
});
}
/**
* @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")
.leftJoinAndSelect("role.permissions", "role_permissions")
.where("role.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("role not found by id", err);
});
}
}