Skip to Content
JavaScript Everywhere
book

JavaScript Everywhere

by Adam D. Scott
February 2020
Intermediate to advanced
344 pages
6h 37m
English
O'Reilly Media, Inc.
Content preview from JavaScript Everywhere

Chapter 8. User Actions

Imagine you had just joined a club (remember the “Secret Club for Super Cool People”?), but when you showed up for the first time there was nothing to do. The club was a big, empty room with people wandering in and out with no way of interacting with the club or one another. I’m a bit of an introvert, so this doesn’t sound that bad, but I wouldn’t be willing to pay a membership fee for it.

Right now our API is essentially a big, useless club. We have a way to create data and a way for users to sign in, but nothing allows a user to own that data. In this chapter, we’ll be addressing this by adding user interactions. We’ll write the code that will enable a user to own the notes they create, limit who can delete or modify a note, and enable users to “favorite” a note that they like. Additionally, we’ll enable API users to make nested queries, allowing our UIs to write simple queries that relate users to notes.

Before We Get Started

In this chapter, we’ll be making some pretty significant changes to our notes files. Since we have a small amount of data in our database, you may find it easier to remove the existing notes from your local database. This isn’t necessary, but can reduce confusion as you work through this chapter.

To do this, we’ll go into the MongoDB shell, ensure that we’re referencing the notedly database (the name of the database in our .env file), and use MongoDB’s .remove() method. From your terminal, type the following:

$ mongo
$ use notedly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Modern JavaScript Bootcamp (2019)

The Modern JavaScript Bootcamp (2019)

Andrew Mead
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781492046974Errata PageSupplemental Content