folder structure
This commit is contained in:
parent
5d3f8ea46a
commit
84e2ec72ac
242 changed files with 635 additions and 635 deletions
44
src/service/user/rolePermissionService.ts
Normal file
44
src/service/user/rolePermissionService.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { rolePermission } from "../../entity/user/role_permission";
|
||||
import { userPermission } from "../../entity/user/user_permission";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class RolePermissionService {
|
||||
/**
|
||||
* @description get permission by role
|
||||
* @param roleId number
|
||||
* @returns {Promise<Array<rolePermission>>}
|
||||
*/
|
||||
static async getByRole(roleId: number): Promise<Array<rolePermission>> {
|
||||
return await dataSource
|
||||
.getRepository(rolePermission)
|
||||
.createQueryBuilder("permission")
|
||||
.where("permission.roleId = :roleId", { roleId: roleId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("permissions not found by role", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get permission by roles
|
||||
* @param roleIds Array<number>
|
||||
* @returns {Promise<Array<rolePermission>>}
|
||||
*/
|
||||
static async getByRoles(roleIds: Array<number>): Promise<Array<rolePermission>> {
|
||||
return await dataSource
|
||||
.getRepository(rolePermission)
|
||||
.createQueryBuilder("permission")
|
||||
.where("permission.roleId IN (:...roleIds)", { roleIds: roleIds })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("permissions not found by roles", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue