BenBolthouse/nice-bytes

List of Users Collections In View Model

Closed this issue · 0 comments

In order to create a dropdown of a user's collections in the view,

  • In GET routes /, /spots/:id and collections/:id
  • Use the session user to query a user's collections where collection name does not equal "Want To Visit" or "Have Visited", and
  • Provide the collection in the view model on the user view model object as user.customCollections, also
  • Do a similar query where collection name does equal "Want To Visit" or "Have Visited", then
  • Send the ID's of both of the above collections as a defaultCollections object on the view model

The resulting view model will look something like this:

res.render(<<pug_template>>, {
    user: {
        firstName: <<firstName>>,
        lastName: <<lastName>>,
        username: <<username>>,
        email: <<email>>,
        customCollections: [
            {
                id: <<collection_id>>,
                name: <<collection_name>>,
            },
            ...
        ]
        defaultCollections: {
            hasVisitedId: <<has_visited_id>>,
            wantToVisitId: <<want_to_visit_id>>,
        }
    },
});