education controller, service, command
This commit is contained in:
parent
5368a96d0f
commit
fded8a663a
29 changed files with 884 additions and 5 deletions
91
src/controller/admin/configuration/educationController.ts
Normal file
91
src/controller/admin/configuration/educationController.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue