26 lines
672 B
TypeScript
26 lines
672 B
TypeScript
import { Request, Response } from 'express';
|
|
import { Marque } from '../types/marque';
|
|
import marqueService from '../services/marque.service';
|
|
import { Either } from '../utils/utils';
|
|
|
|
const register = async (req: Request, res: Response) => {
|
|
if (!req || !req.body || !req.body.name) {
|
|
res.status(400).send();
|
|
return;
|
|
}
|
|
const name: string = req.body.name;
|
|
const marque: Either<Marque, string> = await marqueService.createMarque(name);
|
|
if (marque.hasRight) {
|
|
res.status(403).send(marque.right);
|
|
return;
|
|
}
|
|
|
|
res.status(200).send(marque);
|
|
}
|
|
|
|
const marqueController = {
|
|
register
|
|
};
|
|
|
|
export default marqueController;
|