feat: ajout de la saisie manuel pour purchase.routes

This commit is contained in:
Lazanimady Andrianirindrainy
2026-06-24 14:28:25 +02:00
parent dbdebae45e
commit a707d2785f

View File

@@ -16,11 +16,28 @@ router.get("/", (req,res) => {
<form action="/new-purchase/file" method="POST" enctype="multipart/form-data"> <form action="/new-purchase/file" method="POST" enctype="multipart/form-data">
<input type="file" name="image" multiple> <input type="file" name="image" multiple>
<button type="submit">Envoyer</button> <button type="submit">Envoyer</button>
</form>`; </form>
<form action="/new-purchase/new" method="POST">
<label for="nom_produit">Nom du produit:</label>
<input type="text" name="nom_produit" >
</br>
<label for="quantite">Quantité:</label>
<input type="text" name="quantite" >
</br>
<label for="prixHT">Prix HT:</label>
<input type="text" name="prixHT" >
</br>
<label for="tva">TVA:</label>
<input type="text" name="tva" >
</br>
<button type="submit">Envoyer</button>
</form>
`;
res.send(html); res.send(html);
}); });
// gère la réception d'un ou de plusieurs fichiers PDF
router.post("/file", async (req,res) => { router.post("/file", async (req,res) => {
try { try {
const files = await file_form_handler(req); const files = await file_form_handler(req);
@@ -51,6 +68,23 @@ router.post("/file", async (req,res) => {
} }
}); });
// gère la récéption de produit saisie manuellement
router.post("/new", async (req, res) => {
const nom_produit : string = req.body.nom_produit ;
const quantite : number = Number(req.body.quantite);
const prixHT : number = Number(req.body.prixHT);
const tva : string = req.body.tva;
res.send({
[nom_produit]: {
quantité: quantite,
prixHT: prixHT,
TVA: tva
}
});
});
// fonction pour gérer la récéption des fichier par un form // fonction pour gérer la récéption des fichier par un form
function file_form_handler(req: ExpressRequest): Promise<Files> { function file_form_handler(req: ExpressRequest): Promise<Files> {
return new Promise<Files>((resolve, reject) => { return new Promise<Files>((resolve, reject) => {