After checking if the name already exists, the program keeps running to the next query and still insert data (also shows an error because it sends multiple responses). 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!")
})
}