91 lines
2.6 KiB
TypeScript
91 lines
2.6 KiB
TypeScript
import { Request, Response } from "express";
|
|
import EducationService from "../../../service/configuration/education";
|
|
import EducationFactory from "../../../factory/admin/configuration/education";
|
|
import {
|
|
CreateEducationCommand,
|
|
DeleteEducationCommand,
|
|
UpdateEducationCommand,
|
|
} from "../../../command/configuration/education/educationCommand";
|
|
import EducationCommandHandler from "../../../command/configuration/education/educationCommandHandler";
|
|
|
|
/**
|
|
* @description get all educations
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function getAllEducations(req: Request, res: Response): Promise<any> {
|
|
let educations = await EducationService.getAll();
|
|
|
|
res.json(EducationFactory.mapToBase(educations));
|
|
}
|
|
|
|
/**
|
|
* @description get education by id
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function getEducationById(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
let education = await EducationService.getById(id);
|
|
|
|
res.json(EducationFactory.mapToSingle(education));
|
|
}
|
|
|
|
/**
|
|
* @description create new education
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function createEducation(req: Request, res: Response): Promise<any> {
|
|
const education = req.body.education;
|
|
const description = req.body.description;
|
|
|
|
let createEducation: CreateEducationCommand = {
|
|
education: education,
|
|
description: description,
|
|
};
|
|
await EducationCommandHandler.create(createEducation);
|
|
|
|
res.sendStatus(204);
|
|
}
|
|
|
|
/**
|
|
* @description update education
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function updateEducation(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
const education = req.body.education;
|
|
const description = req.body.description;
|
|
|
|
let updateEducation: UpdateEducationCommand = {
|
|
id: id,
|
|
education: education,
|
|
description: description,
|
|
};
|
|
await EducationCommandHandler.update(updateEducation);
|
|
|
|
res.sendStatus(204);
|
|
}
|
|
|
|
/**
|
|
* @description delete education
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function deleteEducation(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
|
|
let deleteEducation: DeleteEducationCommand = {
|
|
id: id,
|
|
};
|
|
await EducationCommandHandler.delete(deleteEducation);
|
|
|
|
res.sendStatus(204);
|
|
}
|