import { dataSource } from "../data-source"; import { award } from "../entity/award"; import InternalException from "../exceptions/internalException"; import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand"; export default abstract class AwardCommandHandler { /** * @description create award * @param CreateAwardCommand * @returns {Promise} */ static async create(createAward: CreateAwardCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(award) .values({ award: createAward.award, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating award"); }); } /** * @description update award * @param UpdateAwardCommand * @returns {Promise} */ static async update(updateAward: UpdateAwardCommand): Promise { return await dataSource .createQueryBuilder() .update(award) .set({ award: updateAward.award, }) .where("id = :id", { id: updateAward.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed updating award"); }); } /** * @description delete award * @param DeleteAwardCommand * @returns {Promise} */ static async delete(deletAward: DeleteAwardCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(award) .where("id = :id", { id: deletAward.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed deleting award"); }); } }