Files
old-naida/endpoints/cleargroup.js
Naida Vatric 46d32196d9 Initial commit
2019-10-30 23:45:40 +01:00

24 lines
626 B
JavaScript

//Call for clearing all users from group
//
const handleClearGroup = (req, res, db) => {
//Parsing req body
const { reqgroup} =req.body;
//Checking for groupname in table groups and deleting users
db('groups')
.where('groupname', 'ilike', reqgroup)
.del()
.then (count => {
if (count!==0) {
res.json(`Total of ${count} users cleared from group.`)
}
else {
throw err
}
})
.catch (err => res.status(400).json('Error finding group in database.'))
}
module.exports = {
handleClearGroup
}