import { Request, Response } from "express"; import AwardService from "../../../service/settings/awardService"; import AwardFactory from "../../../factory/admin/settings/award"; import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../../command/settings/award/awardCommand"; import AwardCommandHandler from "../../../command/settings/award/awardCommandHandler"; /** * @description get all awards * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} */ export async function getAllAwards(req: Request, res: Response): Promise<any> { let awards = await AwardService.getAll(); res.json(AwardFactory.mapToBase(awards)); } /** * @description get award by id * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} */ export async function getAwardById(req: Request, res: Response): Promise<any> { const id = parseInt(req.params.id); let award = await AwardService.getById(id); res.json(AwardFactory.mapToSingle(award)); } /** * @description create new award * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} */ export async function createAward(req: Request, res: Response): Promise<any> { const award = req.body.award; let createAward: CreateAwardCommand = { award: award, }; await AwardCommandHandler.create(createAward); res.sendStatus(204); } /** * @description update award * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} */ export async function updateAward(req: Request, res: Response): Promise<any> { const id = parseInt(req.params.id); const award = req.body.award; let updateAward: UpdateAwardCommand = { id: id, award: award, }; await AwardCommandHandler.update(updateAward); res.sendStatus(204); } /** * @description delete award * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} */ export async function deleteAward(req: Request, res: Response): Promise<any> { const id = parseInt(req.params.id); let deleteAward: DeleteAwardCommand = { id: id, }; await AwardCommandHandler.delete(deleteAward); res.sendStatus(204); }