Skip to content

New save-palette backend route #191

@mikelbrierly

Description

@mikelbrierly

User Story:

As a developer,
I want to be able to hit a backend route to add a palette to a user,
So that our users data is saved to the DB and can be synced


Acceptance Criteria:

  • Create a new PUT route in index.js at the path "/save-palette"
  • Make sure that the callback function is async. (Here's a good reference for this)
  • If req.user exists, then we want to use the findOneAndUpdate method on our User DB model
    • Use this documentation to build our findOneAndUpdate DB query.
    • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    node/expressThis story primarily features node or express code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions