import { dataSource } from "../../../data-source"; import { role } from "../../../entity/user/role"; import InternalException from "../../../exceptions/internalException"; import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand"; export default abstract class RoleCommandHandler { /** * @description create role * @param CreateRoleCommand * @returns {Promise} */ static async create(createRole: CreateRoleCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(role) .values({ role: createRole.role, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating role", err); }); } /** * @description update role * @param UpdateRoleCommand * @returns {Promise} */ static async update(updateRole: UpdateRoleCommand): Promise { return await dataSource .createQueryBuilder() .update(role) .set({ role: updateRole.role, }) .where("id = :id", { id: updateRole.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed updating role", err); }); } /** * @description delete role * @param DeleteRoleCommand * @returns {Promise} */ static async delete(deleteRole: DeleteRoleCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(role) .where("id = :id", { id: deleteRole.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed deleting role", err); }); } }