mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-27 21:19:09 -05:00
Clean Invites route
This commit is contained in:
parent
49b77c5c03
commit
c23c9b345e
@ -11,17 +11,10 @@ const requireAuth = require('../../util/auth').requireAuth;
|
||||
const verifyScope = require('../../util/verifyScope');
|
||||
const verifyBody = require('../../util/verifyBody');
|
||||
|
||||
|
||||
const updateInviteCount = async (req, next) =>
|
||||
User.updateOne({username: req.username}, {$inc: {inviteCount: 1}}).catch(next);
|
||||
|
||||
const verifyUserHasScope = userScope =>
|
||||
scope => verifyScope(userScope, scope);
|
||||
|
||||
const createParams = [{name: 'scope', instance: Array}];
|
||||
router.post('/create', requireAuth('invite.create'), verifyBody(createParams), wrap(async (req, res, next) => {
|
||||
const scope = req.body.scope;
|
||||
const hasPermission = scope.every(verifyUserHasScope(req.scope));
|
||||
const hasPermission = scope.every(scope => verifyScope(req.scope, scope));
|
||||
if (!hasPermission)
|
||||
return res.status(403).json({message: 'Requested scope exceeds own scope.'});
|
||||
|
||||
@ -35,7 +28,7 @@ router.post('/create', requireAuth('invite.create'), verifyBody(createParams), w
|
||||
|
||||
await Promise.all([
|
||||
Invite.create(invite).catch(next),
|
||||
updateInviteCount(req, next)
|
||||
User.updateOne({username: req.username}, {$inc: {inviteCount: 1}})
|
||||
]);
|
||||
|
||||
res.status(200).json({
|
||||
|
Loading…
Reference in New Issue
Block a user