import { dataSource } from "../../../data-source"; import { education } from "../../../entity/configuration/education"; import DatabaseActionException from "../../../exceptions/databaseActionException"; import { CreateEducationCommand, DeleteEducationCommand, UpdateEducationCommand } from "./educationCommand"; export default abstract class EducationCommandHandler { /** * @description create education * @param {CreateEducationCommand} createEducation * @returns {Promise} */ static async create(createEducation: CreateEducationCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(education) .values({ education: createEducation.education, description: createEducation.description, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new DatabaseActionException("CREATE", "education", err); }); } /** * @description update education * @param {UpdateEducationCommand} updateEducation * @returns {Promise} */ static async update(updateEducation: UpdateEducationCommand): Promise { return await dataSource .createQueryBuilder() .update(education) .set({ education: updateEducation.education, description: updateEducation.description, }) .where("id = :id", { id: updateEducation.id }) .execute() .then(() => {}) .catch((err) => { throw new DatabaseActionException("UPDATE", "education", err); }); } /** * @description delete education * @param {DeleteEducationCommand} deleteEducation * @returns {Promise} */ static async delete(deleteEducation: DeleteEducationCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(education) .where("id = :id", { id: deleteEducation.id }) .execute() .then(() => {}) .catch((err) => { throw new DatabaseActionException("DELETE", "education", err); }); } }