revokeInvite and getInviteByToken functions.

This commit is contained in:
Shane Kilkelly 2016-07-21 16:19:15 +01:00
parent d9c6df0e47
commit 546517db90

View file

@ -35,7 +35,23 @@ module.experts = CollaboratorsInviteHandler =
callback(null, invite) callback(null, invite)
revokeInvite: (projectId, inviteId, callback=(err)->) -> revokeInvite: (projectId, inviteId, callback=(err)->) ->
logger.log {projectId, inviteId}, "removing invite"
ProjectInvite.remove {projectId: projectId, _id: inviteId}, (err) ->
if err?
logger.err {err, projectId, inviteId}, "error removing invite"
return callback(err)
callback(null)
getInviteByToken: (projectId, tokenString, callback=(err,invite)->) -> getInviteByToken: (projectId, tokenString, callback=(err,invite)->) ->
logger.log {projectId, tokenString}, "fetching invite by token"
ProjectInvite.findOne {projectId: projectId, token: tokenString}, (err, invite) ->
if err?
logger.err {err, projectId, inviteId}, "error fetching invite"
return callback(err)
now = new Date()
if invite.expiresAt < now
logger.log {projectId, inviteId, expiresAt: invite.expiresAt}, "invite expired"
return callback(null, null)
callback(null, invite)
acceptInvite: (projectId, inviteId, callback=(err)->) -> acceptInvite: (projectId, inviteId, callback=(err)->) ->