Files
old-naida/endpoints/cleargroup.js

26 lines
709 B
JavaScript
Raw Normal View History

2019-10-30 23:45:40 +01:00
//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
2019-11-01 01:16:23 +01:00
db('groups')
2019-10-30 23:45:40 +01:00
.where('groupname', 'ilike', reqgroup)
2019-11-01 01:16:23 +01:00
//Group initialization is maintained
.andWhereNot('username', '')
2019-10-30 23:45:40 +01:00
.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
}