folder structure
This commit is contained in:
parent
5d3f8ea46a
commit
84e2ec72ac
242 changed files with 635 additions and 635 deletions
43
src/service/user/roleService.ts
Normal file
43
src/service/user/roleService.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue