change folder structure
This commit is contained in:
parent
a332e4d779
commit
a09c75a998
167 changed files with 262 additions and 246 deletions
45
src/service/management/rolePermissionService.ts
Normal file
45
src/service/management/rolePermissionService.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { rolePermission } from "../../entity/management/role_permission";
|
||||
import { userPermission } from "../../entity/management/user_permission";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
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 DatabaseActionException("SELECT", "rolePermission", 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 DatabaseActionException("SELECT", "rolePermission", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue