25 lines
649 B
TypeScript
25 lines
649 B
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { role } from "../entity/role";
|
||
|
import InternalException from "../exceptions/internalException";
|
||
|
|
||
|
export default abstract class RoleService {
|
||
|
/**
|
||
|
* @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")
|
||
|
.where("role.id = :id", { id: id })
|
||
|
.getOneOrFail()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("role not found by id");
|
||
|
});
|
||
|
}
|
||
|
}
|