After chcecking if the name already exist, the program keeps running to the next query and still insert data (also shows error becasue it sends multiple response). How to make it stop after it run if (results.rowCount > 0) ?
const addCategory = (req, res) => {
let { name } = req.body
//check if name exist
pool.query(queries.checkNameExists, [name], (error, results) => {
if (error) throw error
if (results.rowCount > 0) {
return res.status(409).send(`Category ${name} already exists!`)
}
})
//insert new category
pool.query(queries.addCategory, [name], (error, results) => {
if (error) throw error
res.status(201).send("Category created succesfully!")
})
}