Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
awt_cw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Natarajan, Harish (PG/T - Comp Sci & Elec Eng)
awt_cw
Commits
befeecd0
Commit
befeecd0
authored
2 months ago
by
Thyagarajan Sumathi, Varsha (PG/T - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
Changes to idea controller to toggle and get collaboration
parent
1c5c318a
No related branches found
No related tags found
1 merge request
!9
Changes to idea controller to toggle and get collaboration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Startup-app/backend/controllers/ideaController.js
+54
-1
54 additions, 1 deletion
Startup-app/backend/controllers/ideaController.js
with
54 additions
and
1 deletion
Startup-app/backend/controllers/ideaController.js
+
54
−
1
View file @
befeecd0
const
Idea
=
require
(
'
../models/idea
'
);
const
Idea
=
require
(
'
../models/idea
'
);
const
mongoose
=
require
(
'
mongoose
'
);
const
mongoose
=
require
(
'
mongoose
'
);
// Helper function for validating required fields
// Helper function for validating required fields
const
validateFields
=
(
fields
,
res
)
=>
{
const
validateFields
=
(
fields
,
res
)
=>
{
for
(
const
field
of
fields
)
{
for
(
const
field
of
fields
)
{
...
@@ -102,4 +101,58 @@ exports.getLikedPosts = async (req, res) => {
...
@@ -102,4 +101,58 @@ exports.getLikedPosts = async (req, res) => {
console
.
error
(
'
Error fetching liked posts:
'
,
err
.
message
);
console
.
error
(
'
Error fetching liked posts:
'
,
err
.
message
);
res
.
status
(
500
).
json
({
msg
:
'
Failed to fetch liked posts
'
});
res
.
status
(
500
).
json
({
msg
:
'
Failed to fetch liked posts
'
});
}
}
};
// Add or remove a collaborator
exports
.
toggleCollaboration
=
async
(
req
,
res
)
=>
{
try
{
//console.log('Request body:', req.body);
//console.log('Authenticated user:', req.user);
const
{
ideaId
}
=
req
.
body
;
const
userId
=
req
.
user
.
id
;
const
idea
=
await
Idea
.
findById
(
ideaId
);
if
(
!
idea
)
{
console
.
error
(
'
Idea not found:
'
,
ideaId
);
return
res
.
status
(
404
).
json
({
msg
:
'
Idea not found
'
});
}
const
isCollaborating
=
idea
.
collaborators
.
includes
(
userId
);
if
(
isCollaborating
)
{
// Remove collaborator
idea
.
collaborators
=
idea
.
collaborators
.
filter
(
id
=>
id
.
toString
()
!==
userId
);
}
else
{
// Add collaborator
idea
.
collaborators
.
push
(
userId
);
}
await
idea
.
save
();
res
.
status
(
200
).
json
({
msg
:
isCollaborating
?
'
Collaboration reverted
'
:
'
Collaboration requested
'
,
collaborators
:
idea
.
collaborators
,
});
}
catch
(
error
)
{
console
.
error
(
'
Error toggling collaboration:
'
,
error
.
message
);
res
.
status
(
500
).
json
({
msg
:
'
Server error
'
});
}
};
// Get collaborators for an idea
exports
.
getCollaborators
=
async
(
req
,
res
)
=>
{
try
{
const
{
ideaId
}
=
req
.
params
;
const
idea
=
await
Idea
.
findById
(
ideaId
).
populate
(
'
collaborators
'
,
'
name email
'
);
if
(
!
idea
)
{
return
res
.
status
(
404
).
json
({
msg
:
'
Idea not found
'
});
}
res
.
status
(
200
).
json
(
idea
.
collaborators
);
}
catch
(
error
)
{
console
.
error
(
'
Error fetching collaborators:
'
,
error
.
message
);
res
.
status
(
500
).
json
({
msg
:
'
Server error
'
});
}
};
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment