ff-admin-server/src/controller/admin/awardController.ts

84 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-09-04 12:01:22 +00:00
import { Request, Response } from "express";
import AwardService from "../../service/awardService";
import AwardFactory from "../../factory/admin/award";
2024-09-05 14:17:22 +00:00
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand";
import AwardCommandHandler from "../../command/awardCommandHandler";
2024-09-04 12:01:22 +00: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 14:17:22 +00:00
let createAward: CreateAwardCommand = {
award: award,
};
await AwardCommandHandler.create(createAward);
2024-09-04 12:01:22 +00: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 14:17:22 +00:00
let updateAward: UpdateAwardCommand = {
id: id,
award: award,
};
await AwardCommandHandler.update(updateAward);
2024-09-04 12:01:22 +00: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 14:17:22 +00:00
let deleteAward: DeleteAwardCommand = {
id: id,
};
await AwardCommandHandler.delete(deleteAward);
2024-09-04 12:01:22 +00:00
res.sendStatus(204);
}