@@ -37,10 +37,12 @@ const marketplaceController: MarketplaceController = {
37
37
* @return sends the updated entire project document to the frontend
38
38
*/
39
39
publishProject : async ( req , res , next ) => {
40
- const { _id, project, comments, userId, username, name } = req . body ;
40
+ const { _id, project, comments, name } = req . body ;
41
+ const username = req . cookies . username ;
42
+ const userId = req . cookies . ssid ;
41
43
const createdAt = Date . now ( ) ;
42
44
43
- if ( userId === req . cookies . ssid ) {
45
+ try {
44
46
if ( mongoose . isValidObjectId ( _id ) ) {
45
47
const noPub = { ...project }
46
48
delete noPub . published ;
@@ -67,7 +69,7 @@ const marketplaceController: MarketplaceController = {
67
69
return next ( ) ;
68
70
}
69
71
}
70
- else {
72
+ catch {
71
73
72
74
// we should not expect a user to be able to access another user's id, but included error handling for unexpected errors
73
75
return next ( {
@@ -85,12 +87,12 @@ const marketplaceController: MarketplaceController = {
85
87
* @return sends the updated project to the frontend
86
88
*/
87
89
unpublishProject : ( req , res , next ) => {
88
- // pull project name and userId from req.body
89
- const { _id , userId } = req . body ;
90
+ const { _id } = req . body ;
91
+ const userId = req . cookies . ssid ;
90
92
//check if req.cookies.ssid matches userId
91
93
92
- if ( userId === req . cookies . ssid ) {
93
- Projects . findOneAndUpdate ( { _id } , { published : false } , { new : true } , ( err , result ) => {
94
+ try {
95
+ Projects . findOneAndUpdate ( { _id, userId } , { published : false } , { new : true } , ( err , result ) => {
94
96
if ( err || result === null ) {
95
97
return next ( {
96
98
log : `Error in marketplaceController.unpublishProject: ${ err || null } ` ,
@@ -103,7 +105,7 @@ const marketplaceController: MarketplaceController = {
103
105
return next ( ) ;
104
106
} ) ;
105
107
}
106
- else {
108
+ catch {
107
109
// we should not expect a user to be able to access another user's id, but included error handling for unexpected errors
108
110
return next ( {
109
111
log : `Error in marketplaceController.unpublishProject` ,
0 commit comments