Initial commit
This commit is contained in:
23
endpoints/cleargroup.js
Normal file
23
endpoints/cleargroup.js
Normal file
@@ -0,0 +1,23 @@
|
||||
//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
|
||||
}
|
||||
Reference in New Issue
Block a user