[ ] Because palettes is an array, we can use the mongo $push operator to append our new palette to the array rather than replace the whole thing.
[ ] We also want to return the updated document from this route so that we can immediately display the newly added changes in the browser
[ ] Use Postman to test this new api endpoint (remember for this to work you'll need to be logged into Halogen or else there won't be a user in req.user).
Note: When creating a REST API, the PUT route is used to update an existing document, while POST is used to create a new one.
User Story:
Acceptance Criteria:
PUT
route inindex.js
at the path "/save-palette"async
. (Here's a good reference for this)req.user
exists, then we want to use thefindOneAndUpdate
method on ourUser
DB modelfindOneAndUpdate
DB query.palettes
is an array, we can use the mongo$push
operator to append our new palette to the array rather than replace the whole thing.req.user
).Note: When creating a REST API, the
PUT
route is used to update an existing document, whilePOST
is used to create a new one.