Skip to content

Commit

Permalink
Merge pull request #16 from jhotmann/small-improvements
Browse files Browse the repository at this point in the history
Fix a couple 0.2.0 bugs
  • Loading branch information
jhotmann authored Oct 14, 2021
2 parents 3d7bd46 + a8174ef commit 20973bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions routes/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ router.get('/leave/:groupId', db.mwUser, async (req, res) => {
res.redirect('/user');
});

router.get('/delete/:groupId', db.mwUser, db.mwGroup, isGroupAdmin, async (req, res) => {
await db.deleteGroup(req.params.groupId);
res.redirect('/user');
});

module.exports = router;
38 changes: 26 additions & 12 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,25 @@ module.exports.getUserGroups = async (userId) => {

// User Groups Middleware - depends upon mwUser
module.exports.mwUserGroups = async (req, res, next) => {
const userId = req.pageData.userData._id;
if (req.pageData.userData) {
const userGroups = await this.getUserGroups(userId);
req.pageData.userGroups = await async.mapSeries(userGroups, async (group) => {
group.memberNames = await async.mapSeries(group.members, async (member) => {
const userData = await this.getUser(member.userId);
return userData.username;
if (!req.pageData.userData) {
req.pageData.userGroups = [];
next();
} else {
const userId = req.pageData.userData._id;
if (req.pageData.userData) {
const userGroups = await this.getUserGroups(userId);
req.pageData.userGroups = await async.mapSeries(userGroups, async (group) => {
group.memberNames = await async.mapSeries(group.members, async (member) => {
const userData = await this.getUser(member.userId);
return userData.username;
});
group.isAdmin = group.adminId === userId;
group.accepted = group.members.find((member) => member.userId === userId).accepted;
return group;
});
group.isAdmin = group.adminId === userId;
group.accepted = group.members.find((member) => member.userId === userId).accepted;
return group;
});
}
next();
}
next();
};

module.exports.inviteToGroup = async (_id, userId) => {
Expand Down Expand Up @@ -285,6 +290,15 @@ module.exports.leaveGroup = async (_id, userId) => {
}
};

module.exports.deleteGroup = async (_id) => {
try {
return await db.groups.remove({ _id });
} catch (err) {
console.log(err);
return null;
}
};

// !!!! Registration !!!!

module.exports.createRegistration = async () => {
Expand Down

0 comments on commit 20973bb

Please sign in to comment.