87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import { Request, Response } from "express";
|
|
import SalutationService from "../../../service/settings/salutationService";
|
|
import SalutationFactory from "../../../factory/admin/settings/salutation";
|
|
import {
|
|
CreateSalutationCommand,
|
|
DeleteSalutationCommand,
|
|
UpdateSalutationCommand,
|
|
} from "../../../command/settings/salutation/salutationCommand";
|
|
import SalutationCommandHandler from "../../../command/settings/salutation/salutationCommandHandler";
|
|
|
|
/**
|
|
* @description get all salutations
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function getAllSalutations(req: Request, res: Response): Promise<any> {
|
|
let salutations = await SalutationService.getAll();
|
|
|
|
res.json(SalutationFactory.mapToBase(salutations));
|
|
}
|
|
|
|
/**
|
|
* @description get salutation by id
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function getSalutationById(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
let salutation = await SalutationService.getById(id);
|
|
|
|
res.json(SalutationFactory.mapToSingle(salutation));
|
|
}
|
|
|
|
/**
|
|
* @description create new salutation
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function createSalutation(req: Request, res: Response): Promise<any> {
|
|
const salutation = req.body.salutation;
|
|
|
|
let createSalutation: CreateSalutationCommand = {
|
|
salutation: salutation,
|
|
};
|
|
await SalutationCommandHandler.create(createSalutation);
|
|
|
|
res.sendStatus(204);
|
|
}
|
|
|
|
/**
|
|
* @description update salutation
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function updateSalutation(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
const salutation = req.body.salutation;
|
|
|
|
let updateSalutation: UpdateSalutationCommand = {
|
|
id: id,
|
|
salutation: salutation,
|
|
};
|
|
await SalutationCommandHandler.update(updateSalutation);
|
|
|
|
res.sendStatus(204);
|
|
}
|
|
|
|
/**
|
|
* @description delete salutation
|
|
* @param req {Request} Express req object
|
|
* @param res {Response} Express res object
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export async function deleteSalutation(req: Request, res: Response): Promise<any> {
|
|
const id = parseInt(req.params.id);
|
|
|
|
let deleteSalutation: DeleteSalutationCommand = {
|
|
id: id,
|
|
};
|
|
await SalutationCommandHandler.delete(deleteSalutation);
|
|
|
|
res.sendStatus(204);
|
|
}
|