1 Commits

Author SHA1 Message Date
Lazanimady Andrianirindrainy
a707d2785f feat: ajout de la saisie manuel pour purchase.routes 2026-06-24 14:28:25 +02:00

View File

@@ -16,11 +16,28 @@ router.get("/", (req,res) => {
<form action="/new-purchase/file" method="POST" enctype="multipart/form-data">
<input type="file" name="image" multiple>
<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);
});
// gère la réception d'un ou de plusieurs fichiers PDF
router.post("/file", async (req,res) => {
try {
const files = await file_form_handler(req);
@@ -38,7 +55,7 @@ router.post("/file", async (req,res) => {
}
const results_of_parsing = [];
for (const path of file_paths) {
results_of_parsing.push(await pdf_parse(path));
};
@@ -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
function file_form_handler(req: ExpressRequest): Promise<Files> {
return new Promise<Files>((resolve, reject) => {