Files
old-naida/endpoints/cleargroup.js
2019-11-01 01:16:23 +01:00

26 lines
709 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)
//Group initialization is maintained
.andWhereNot('username', '')
.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
}