2024-09-04 14:01:22 +02:00
|
|
|
import { Request, Response } from "express";
|
2025-01-05 14:14:00 +01:00
|
|
|
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";
|
2024-09-04 14:01:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
|
2024-09-05 16:17:22 +02:00
|
|
|
let createAward: CreateAwardCommand = {
|
|
|
|
award: award,
|
|
|
|
};
|
|
|
|
await AwardCommandHandler.create(createAward);
|
|
|
|
|
2024-09-04 14:01:22 +02:00
|
|
|
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;
|
|
|
|
|
2024-09-05 16:17:22 +02:00
|
|
|
let updateAward: UpdateAwardCommand = {
|
|
|
|
id: id,
|
|
|
|
award: award,
|
|
|
|
};
|
|
|
|
await AwardCommandHandler.update(updateAward);
|
|
|
|
|
2024-09-04 14:01:22 +02:00
|
|
|
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);
|
|
|
|
|
2024-09-05 16:17:22 +02:00
|
|
|
let deleteAward: DeleteAwardCommand = {
|
|
|
|
id: id,
|
|
|
|
};
|
|
|
|
await AwardCommandHandler.delete(deleteAward);
|
|
|
|
|
2024-09-04 14:01:22 +02:00
|
|
|
res.sendStatus(204);
|
|
|
|
}
|