Whenever I hit this api with sending this
[{"project_id": "knsfviv9",
"coach_id": ""
},
{"project_id": "ovsijiov9",
"coach_id": ""
}]
it inserts into database but it gives response 0 as the result variable remains 0. result variable gets incremented but in res.send it sends 0. can someone help me with this?
app.post('/api/patc/:id', (req, res) => {
let projectList = req.body;
projectList.forEach(element => {
let data = {
patc_id: "patc-" + randomID(),
college_id: req.params.id,
project_id: element.project_id,
coach_id: element.coach_id,
date: NOW()
};
let sql = "INSERT INTO projects_assigned_to_colleges SET ?";
conn.query(sql, data, (err, results) => {
if (err) throw err;
result.push(results);
});
});
res.send(JSON.stringify({ "status": 200, "error": null, "response": result }));
});