fix: fix fix of fix
This commit is contained in:
parent
b49de74a4b
commit
d9c9830ec5
@ -38,7 +38,7 @@ const allBoxesFromDate: RequestHandler<{ date: string; }> = async (req, res) =>
|
||||
res.render('boxes.ejs', { boxes });
|
||||
};
|
||||
|
||||
const boxAddPieces: RequestHandler<{ title: string|number; }> = async (req, res) => {
|
||||
const boxAddPieces: RequestHandler<{ title: string; }> = async (req, res) => {
|
||||
const boxEither: Either<Box, string> = await boxService.getBox(req.params.title);
|
||||
|
||||
if (boxEither.hasRight) {
|
||||
@ -62,6 +62,34 @@ const boxAddPieces: RequestHandler<{ title: string|number; }> = async (req, res)
|
||||
res.redirect(`/boxes/${req.params.title}`);
|
||||
};
|
||||
|
||||
const boxAddPiecesById: RequestHandler<{ id_box: string; }> = async (req, res) => {
|
||||
if (isNaN(parseInt(req.params.id_box))) {
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
const boxEither: Either<Box, string> = await boxService.getBox(parseInt(req.params.id_box));
|
||||
|
||||
if (boxEither.hasRight) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const piece: Either<Piece, string> = await getPiece(req.body.numero_piece);
|
||||
if (piece.hasRight) {
|
||||
res.status(404).send(eitherFormatError(piece));
|
||||
return;
|
||||
}
|
||||
|
||||
if (boxEither.left.pieces.map(p => p.first.id_piece).includes(piece.left.id_piece)) {
|
||||
res.status(401).send({});
|
||||
return;
|
||||
}
|
||||
|
||||
await boxService.addPiecesToBox(boxEither.left.id, piece.left.id_piece, req.body.quantite);
|
||||
|
||||
res.redirect(`/boxes/byid/${req.params.id_box}`);
|
||||
};
|
||||
|
||||
const boxRemovePiece: RequestHandler<{ title: string; }> = async (req, res) => {
|
||||
const boxEither: Either<Box, string> = await boxService.getBox(req.params.title);
|
||||
|
||||
@ -87,6 +115,10 @@ const boxRemovePiece: RequestHandler<{ title: string; }> = async (req, res) => {
|
||||
};
|
||||
|
||||
const boxRemovePieceById: RequestHandler<{ id_box: string; }> = async (req, res) => {
|
||||
if (isNaN(parseInt(req.params.id_box))) {
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
const boxEither: Either<Box, string> = await boxService.getBox(parseInt(req.params.id_box));
|
||||
|
||||
if (boxEither.hasRight) {
|
||||
@ -150,6 +182,7 @@ const registerBox: RequestHandler = async (req, res, next) => {
|
||||
|
||||
const boxController = {
|
||||
boxAddPieces,
|
||||
boxAddPiecesById,
|
||||
boxRemovePiece,
|
||||
boxByTitle,
|
||||
allBoxes,
|
||||
|
@ -14,7 +14,7 @@ boxRouter.post("/:title", boxController.boxAddPieces);
|
||||
|
||||
|
||||
boxRouter.delete("/byid/:id_box", boxController.boxRemovePieceById);
|
||||
boxRouter.post("/byid/:id_box", boxController.boxAddPieces);
|
||||
boxRouter.post("/byid/:id_box", boxController.boxAddPiecesById);
|
||||
boxRouter.delete("/:title", boxController.boxRemovePiece);
|
||||
boxRouter.get("/byid/:id", boxController.boxById);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user