I have a query which has 2 tables First is prodstock table and second is stockmaster so now I want to perform a query using a function in that when I call one function I want to update both tables by two queries but I can't which I am showing more widely in following
This is stockmaster table
This is prodstock table
here is the code of the function
export const postStock = (body) => {
let sql = ` INSERT INTO stockmaster (stocknum, cat_id, user_id, dyenumber, stockQty, price,stockform, remark) VALUES ('${body.stocknum}', '${body.cat_id}', '${body.user_id}', '${body.dyenumber}', '${body.stockQty}', '${body.price}', '${body.stockform}', '${body.remark}')`;
return sql;
};
export const updateprodStock = (cat_id, dyenumber, stockQty) => {
let sql = `UPDATE prodstock JOIN stockmaster ON prodstock.cat_id = '${cat_id}' AND prodstock.dyenumber = '${dyenumber}' SET prodstock.total_qty = prodstock.total_qty + '${stockQty} `
return sql}
and here where both function are called
static stock = (req, res) => {
const { cat_id, dyenumber, stockQty } = req.body;
connection.query(postStock(req.body), (err, result) => {
if (err) {
throw new Error(err);
} else {
connection.query(updateprodStock(cat_id, dyenumber, stockQty))
res.status(200).json({
code: 1,
msg: "success",
data: result
})
}
})
}
so when I perform poststock function I also want to execute updateprodStock so that in one function stock will update and the total qty will be updated but is not working does anybody can help??

