change folder structure
This commit is contained in:
parent
a332e4d779
commit
a09c75a998
167 changed files with 262 additions and 246 deletions
44
src/service/management/inviteService.ts
Normal file
44
src/service/management/inviteService.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { invite } from "../../entity/management/invite";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class InviteService {
|
||||
/**
|
||||
* @description get all invites
|
||||
* @returns {Promise<Array<invite>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<invite>> {
|
||||
return await dataSource
|
||||
.getRepository(invite)
|
||||
.createQueryBuilder("invite")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "invite", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get invite by id
|
||||
* @param mail string
|
||||
* @param token string
|
||||
* @returns {Promise<invite>}
|
||||
*/
|
||||
static async getByMailAndToken(mail: string, token: string): Promise<invite> {
|
||||
return await dataSource
|
||||
.getRepository(invite)
|
||||
.createQueryBuilder("invite")
|
||||
.where("invite.mail = :mail", { mail: mail })
|
||||
.andWhere("invite.token = :token", { token: token })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "invite", err);
|
||||
});
|
||||
}
|
||||
}
|
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);
|
||||
});
|
||||
}
|
||||
}
|
45
src/service/management/roleService.ts
Normal file
45
src/service/management/roleService.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { role } from "../../entity/management/role";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
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")
|
||||
.orderBy("role", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "roles", 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 DatabaseActionException("SELECT", "role", err);
|
||||
});
|
||||
}
|
||||
}
|
25
src/service/management/userPermissionService.ts
Normal file
25
src/service/management/userPermissionService.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { userPermission } from "../../entity/management/user_permission";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class UserPermissionService {
|
||||
/**
|
||||
* @description get permission by user
|
||||
* @param userId string
|
||||
* @returns {Promise<Array<userPermission>>}
|
||||
*/
|
||||
static async getByUser(userId: string): Promise<Array<userPermission>> {
|
||||
return await dataSource
|
||||
.getRepository(userPermission)
|
||||
.createQueryBuilder("permission")
|
||||
.where({ userId: userId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "userPermission", err);
|
||||
});
|
||||
}
|
||||
}
|
132
src/service/management/userService.ts
Normal file
132
src/service/management/userService.ts
Normal file
|
@ -0,0 +1,132 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { role } from "../../entity/management/role";
|
||||
import { user } from "../../entity/management/user";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class UserService {
|
||||
/**
|
||||
* @description get users
|
||||
* @returns {Promise<Array<user>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<user>> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.leftJoinAndSelect("user.roles", "roles")
|
||||
.leftJoinAndSelect("user.permissions", "permissions")
|
||||
.leftJoinAndSelect("roles.permissions", "role_permissions")
|
||||
.orderBy("firstname", "ASC")
|
||||
.addOrderBy("lastname", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "user", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get user by id
|
||||
* @param id string
|
||||
* @returns {Promise<user>}
|
||||
*/
|
||||
static async getById(id: string): Promise<user> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.leftJoinAndSelect("user.roles", "roles")
|
||||
.leftJoinAndSelect("user.permissions", "permissions")
|
||||
.leftJoinAndSelect("roles.permissions", "role_permissions")
|
||||
.where("user.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "user", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get user by username
|
||||
* @param username string
|
||||
* @returns {Promise<user>}
|
||||
*/
|
||||
static async getByUsername(username: string): Promise<user> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.where("user.username = :username", { username: username })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "user", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get users by mail or username
|
||||
* @param username string
|
||||
* @param mail string
|
||||
* @returns {Promise<Array<user>>}
|
||||
*/
|
||||
static async getByMailOrUsername(mail?: string, username?: string): Promise<Array<user>> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.where("user.mail = :mail", { mail: mail })
|
||||
.orWhere("user.username = :username", { username: username })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "user", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get count of users
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async count(): Promise<number> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.getCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("COUNT", "users", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get roles assigned to user
|
||||
* @param userId string
|
||||
* @returns {Promise<Array<role>>}
|
||||
*/
|
||||
static async getAssignedRolesByUserId(userId: string): Promise<Array<role>> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.leftJoinAndSelect("user.roles", "roles")
|
||||
.leftJoinAndSelect("roles.permissions", "role_permissions")
|
||||
.where("user.id = :id", { id: userId })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res.roles;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "userRoles", err);
|
||||
});
|
||||
}
|
||||
}
|
25
src/service/management/webapiPermissionService.ts
Normal file
25
src/service/management/webapiPermissionService.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { webapiPermission } from "../../entity/management/webapi_permission";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class WebapiPermissionService {
|
||||
/**
|
||||
* @description get permission by api
|
||||
* @param webapiId number
|
||||
* @returns {Promise<Array<webapiPermission>>}
|
||||
*/
|
||||
static async getByApi(webapiId: number): Promise<Array<webapiPermission>> {
|
||||
return await dataSource
|
||||
.getRepository(webapiPermission)
|
||||
.createQueryBuilder("webapi_permission")
|
||||
.where("webapi_permission.webapiId = :webapiId", { webapiId: webapiId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "webapiPermission", err);
|
||||
});
|
||||
}
|
||||
}
|
84
src/service/management/webapiService.ts
Normal file
84
src/service/management/webapiService.ts
Normal file
|
@ -0,0 +1,84 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { webapi } from "../../entity/management/webapi";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class WebapiService {
|
||||
/**
|
||||
* @description get apis
|
||||
* @returns {Promise<Array<webapi>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<webapi>> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "webapi", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by id
|
||||
* @param id number
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getById(id: number): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.where("webapi.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "webapi", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by token
|
||||
* @param token string
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getByToken(token: string): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.where("webapi.token = :token", { token: token })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "webapi", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by id
|
||||
* @param id number
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getTokenById(id: number): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.select("webapi.token")
|
||||
.where("webapi.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "webapi", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue