+ Sample Response
+
+ {
+ "message": "Updated the following items",
+ "updatedFields": {
+ "name": "wonderful API 3"
+ }
+ }
+
+
diff --git a/routes/projects.js b/routes/projects.js
index 7c2a96b..537ad0e 100644
--- a/routes/projects.js
+++ b/routes/projects.js
@@ -44,4 +44,36 @@ app.post( '/', async ( { body }, res, next ) => {
} catch ( err ) { return next( err ) }
} )
+// Update a project using ID
+app.patch( '/:projectId', async (
+ {
+ body,
+ params: { projectId },
+ },
+ res,
+ next,
+) => {
+ try {
+ if ( await GetItemById( ProjectSchema, projectId ) ) {
+ const updatedFields = {}
+
+ // Add all the incoming fields to object
+ Object.keys( body )
+ .filter( key => key !== 'contributors' ) // Doesn't support updating contributors
+ .forEach( key => { updatedFields[ key ] = body[ key ] } )
+
+ // Format dates
+ Object.keys( body )
+ .filter( key => key === 'createdDate' )
+ .forEach( key => { updatedFields[ key ] = FormatDateTime( body[ key ] ) } )
+
+ // update the fields in DB
+ await ProjectSchema.updateOne( { _id: projectId }, { $set: updatedFields } ).exec()
+
+ return res.json( { message: 'Updated the following items', updatedFields } )
+ }
+ return next( DnE( projectId ) )
+ } catch ( err ) { return next( err ) }
+} )
+
export default app