Skip to content
Snippets Groups Projects
Commit 2e663733 authored by Sebastian's avatar Sebastian
Browse files

feat(component-invite): fix get invitations

parent a2702588
No related branches found
No related tags found
No related merge requests found
......@@ -46,9 +46,11 @@ const CollectionsInvitations = app => {
require(`${routePath}/post`)(app.locals.models),
)
/**
* @api {get} /api/collections/:collectionId/invitations List collections invitations
* @api {get} /api/collections/:collectionId/invitations/{:invitationId}?role=:role List collections invitations
* @apiGroup CollectionsInvitations
* @apiParam {collectionId} id Collection id
* @apiParam {id} collectionId Collection id
* @apiParam {id} [invitationId] Invitation id
* @apiParam {String} role The role to search for: handlingEditor, reviewer, author
* @apiSuccessExample {json} Success
* HTTP/1.1 200 OK
* [{
......@@ -56,6 +58,7 @@ const CollectionsInvitations = app => {
* "timestamp": "123223121",
* "email": "email@example.com",
* "status": "pending",
* "invitationId": "1990881"
* }]
* @apiErrorExample {json} List errors
* HTTP/1.1 403 Forbidden
......
......@@ -11,8 +11,8 @@ const getInvitationData = (invitations, userId, role) => {
status = 'refused'
}
const { timestamp } = matchingInvitation
return { timestamp, status }
const { timestamp, id } = matchingInvitation
return { timestamp, status, id }
}
const setupInvitation = async (userId, role, collection) => {
......
......@@ -5,10 +5,10 @@ const inviteHelper = require('../../helpers/Invitation')
const configRoles = config.get('roles')
module.exports = models => async (req, res) => {
const { userId, role } = req.query
const { role } = req.query
// TO DO: authsome
if (!helpers.checkForUndefinedParams(userId, role)) {
res.status(400).json({ error: 'User ID and Role are required' })
if (!helpers.checkForUndefinedParams(role)) {
res.status(400).json({ error: 'Role is required' })
return
}
......@@ -32,11 +32,12 @@ module.exports = models => async (req, res) => {
return
}
// TO DO: handle case for when the invitationID is provided
const membersData = members.map(async member => {
const user = await models.User.find(member)
const { timestamp, status } = inviteHelper.getInvitationData(
const { timestamp, status, id } = inviteHelper.getInvitationData(
collection.invitations,
userId,
user.id,
role,
)
return {
......@@ -44,6 +45,7 @@ module.exports = models => async (req, res) => {
timestamp,
email: user.email,
status,
invitationId: id,
}
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment