Skip to content

Commit bcd61c1

Browse files
committed
created new controller to manage projects
1 parent c455516 commit bcd61c1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/controllers/projectController.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ projectController.saveProject = (req, res, next) => {
1010
// pull ssid from cookies for user id
1111
const userId = req.cookies.ssid;
1212
Projects.findOneAndUpdate(
13+
// looks in projects collection for project by user and name
1314
{ name, userId },
14-
// pushes the saved project into projects array of project
15+
// update or insert the project
1516
{ project },
16-
// this options returns as result the new project that was saved, otherwise result would be the projects array before it was updated
17+
// Options: upsert: true - if none found, inserts new project, if found, updates project
18+
// new: true - returns updated document not the original one
1719
{ upsert: true, new: true },
1820
(err, result) => {
1921
if (err) {

0 commit comments

Comments
 (0)