import { dataSource } from "../data-source"; import { executivePosition } from "../entity/executivePosition"; import InternalException from "../exceptions/internalException"; import { CreateExecutivePositionCommand, DeleteExecutivePositionCommand, UpdateExecutivePositionCommand, } from "./executivePositionCommand"; export default abstract class ExecutivePositionCommandHandler { /** * @description create executivePosition * @param CreateExecutivePositionCommand * @returns {Promise} */ static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(executivePosition) .values({ position: createExecutivePosition.position, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating executivePosition"); }); } /** * @description update executivePosition * @param UpdateExecutivePositionCommand * @returns {Promise} */ static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise { return await dataSource .createQueryBuilder() .update(executivePosition) .set({ positon: updateExecutivePosition.position, }) .where("id = :id", { id: updateExecutivePosition.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed updating executivePosition"); }); } /** * @description delete executivePosition * @param DeleteExecutivePositionCommand * @returns {Promise} */ static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(executivePosition) .where("id = :id", { id: deletExecutivePosition.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed deleting executivePosition"); }); } }