@@ -37,10 +37,12 @@ const marketplaceController: MarketplaceController = {
3737 * @return sends the updated entire project document to the frontend
3838 */
3939 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 ;
4143 const createdAt = Date . now ( ) ;
4244
43- if ( userId === req . cookies . ssid ) {
45+ try {
4446 if ( mongoose . isValidObjectId ( _id ) ) {
4547 const noPub = { ...project }
4648 delete noPub . published ;
@@ -67,7 +69,7 @@ const marketplaceController: MarketplaceController = {
6769 return next ( ) ;
6870 }
6971 }
70- else {
72+ catch {
7173
7274 // we should not expect a user to be able to access another user's id, but included error handling for unexpected errors
7375 return next ( {
@@ -85,12 +87,12 @@ const marketplaceController: MarketplaceController = {
8587 * @return sends the updated project to the frontend
8688 */
8789 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 ;
9092 //check if req.cookies.ssid matches userId
9193
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 ) => {
9496 if ( err || result === null ) {
9597 return next ( {
9698 log : `Error in marketplaceController.unpublishProject: ${ err || null } ` ,
@@ -103,7 +105,7 @@ const marketplaceController: MarketplaceController = {
103105 return next ( ) ;
104106 } ) ;
105107 }
106- else {
108+ catch {
107109 // we should not expect a user to be able to access another user's id, but included error handling for unexpected errors
108110 return next ( {
109111 log : `Error in marketplaceController.unpublishProject` ,
0 commit comments