All i need to do is to send my state of invoice details to database through post request but im having troubles doing it is this the right way to do it or am i missing something post function works fine if the query is only a string so the only problem is reading the body params
const postInvoices = () => {
const URL = "http://localhost:8000/api/InvSave";
axios
.post(URL,InvDet)
.then((response) => {
console.log("DATA : ",response);
})
.catch((error) => {
console.log(error);
});
};
im sending the state on click
in my api i wrote :
router.route('/InvSave').post((request,response)=>{
try{
const invoices = request.body
dboperations.PostInvoices(invoices).then(result => {
response.status(201).json("api results :",result);
})
}catch(err){
console.error(err)
}
})
const PostInvoices = async (invoices) => {
try {
let pool = await sql.connect(configInsert);
console.log("invoices code",CODE_ART)
const q =
"insert into Packingdetails values('1','"+
invoices.CODE_ART +
"','" +
invoices.a_code +
"','" +
invoices.DESC_ART +
"','" +
invoices.TotalPc +
"','" +
invoices.date+
"')";
console.log("query : "+q)
let invs = await pool.query(q);
console.log("saved");
return invs.recordsets;
} catch (err) {
console.log("POSTINV : ", err.message);
}
};
make sure you are using some kind of body-parser to parse your request
console.log(invoices)
to check if you are getting the correct invoices in request body