-
Notifications
You must be signed in to change notification settings - Fork 348
Feature/backend/list of collaborators #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
44c306c
6cbec47
237f62c
064e34f
2796052
40e8f81
b32d02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,24 +14,28 @@ export const invitationToCollaborate = async(req, res)=>{ | |
const user = await User.findById(userid); | ||
if(!user) return res.status(404).json({error: "User not found!"}); | ||
const projectToCollaborate = await Project.findOne({project_id: project_id}).populate("author", "personal_info.email"); | ||
|
||
if(user._id.toString() === projectToCollaborate.author._id.toString()){ | ||
return res.status(400).json({error: "You cannot invite yourself to collaborate on your own project."}); | ||
} | ||
|
||
|
||
|
||
if(!projectToCollaborate) return res.status(404).json({error: "Project not found!"}); | ||
|
||
const authorEmail = projectToCollaborate.author.personal_info.email; | ||
const token = crypto.randomBytes(16).toString('hex'); | ||
|
||
|
||
|
||
const baseUrl = `http://localhost:${process.env.PORT || 8000}`; | ||
|
||
|
||
const acceptLink = `${baseUrl}/api/collaboration/accept/${token}`; | ||
const rejectLink = `${baseUrl}/api/collaboration/reject/${token}`; | ||
|
||
|
||
|
||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: authorEmail, | ||
|
@@ -67,6 +71,16 @@ export const invitationToCollaborate = async(req, res)=>{ | |
|
||
|
||
|
||
export const getListOfCollaborators = async(req, res)=>{ | ||
const userid = req.user; | ||
const {project_id} = req.params; | ||
try { | ||
const existingCollaborators = await collaboration.find({project_id: project_id, author_id: userid}); | ||
if(!existingCollaborators) return res.status(404).json({error: "No collaborators found!"}); | ||
return res.status(200).json({collaborators: existingCollaborators}); | ||
} catch (error) { | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about after |
||
export const acceptInvitation = async(req, res)=>{ | ||
const token = req.params.token; | ||
const id = req.user; | ||
|
@@ -85,6 +99,7 @@ export const acceptInvitation = async(req, res)=>{ | |
} | ||
} | ||
|
||
|
||
export const rejectInvitation = async(req,res)=>{ | ||
const token = req.params.token; | ||
const id = req.user; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep your only 1 route for get all collaborators and remove all your rest changes |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the changes from this file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary line additions?