This repo contains the code for homework assignment #2 of The Node.js Master Class.
You are building the API for a pizza-delivery company. Don't worry about a frontend, just build the API. Here's the spec from your project manager:
-
New users can be created, their information can be edited, and they can be deleted. We should store their name, email address, and street address.
-
Users can log in and log out by creating or destroying a token.
-
When a user is logged in, they should be able to GET all the possible menu items (these items can be hardcoded into the system).
-
A logged-in user should be able to fill a shopping cart with menu items
-
A logged-in user should be able to create an order. You should integrate with the Sandbox of Stripe.com to accept their payment. Note: Use the stripe sandbox for your testing. Follow this link and click on the "tokens" tab to see the fake tokens you can use server-side to confirm the integration is working: https://stripe.com/docs/testing#cards
-
When an order is placed, you should email the user a receipt. You should integrate with the sandbox of Mailgun.com for this. Note: Every Mailgun account comes with a sandbox email account domain (whatever@sandbox123.mailgun.org) that you can send from by default. So, there's no need to setup any DNS for your domain for this task https://documentation.mailgun.com/en/latest/faqs.html#how-do-i-pick-a-domain-name-for-my-mailgun-account
This is an open-ended assignment. You may take any direction you'd like to go with it, as long as your project includes the requirements. It can include anything else you wish as well.
Ensure you have node 8+ installed, and run:
$ NODE_DEBUG=server,stripe,worker node index.js
Import postman_collection.json into Postman to ease API testing.
Fastest way to place an order is:
Check API status with:
$ curl localhost:3000/ping
Required fields:
- name: string
- email: string
- address: string
- password: string
- tosAgreement: boolean
$ curl POST /users
Required fields:
- email: string
Requires token header for authentication.
$ curl GET /users/:email
Required fields:
- email: string
Optional fields (at least one is required):
- name: string
- address: string
- password: string
Requires token header for authentication.
$ curl PUT /users/:email
Required fields:
- email: string
Requires token header for authentication.
$ curl DELETE /users/:email
Required fields:
- email: string
- password: string
$ curl POST /tokens
Required fields:
- id: string
$ curl GET /tokens/:id
Required fields:
- id: string
- extend: boolean
$ curl PUT /tokens/:id
Required fields:
- id: string
$ curl DELETE /tokens/:id
Requires token header for authentication.
$ curl Get /menu
Each user has only one cart. A cart may contain any number of menu items.
Requires token header for authentication.
$ curl GET /cart
Adds or substracts menu items from cart. Positive values of quantity increment, negative values decrement.
Required fields:
- menu_item_id: string
- quantity: integer
Requires token header for authentication.
$ curl PUT /cart
Empties the cart or a single item
Optional fields:
- menu_item_id: string
Requires token header for authentication.
$ curl DELETE /cart?menu_item_id
Creates an order based on the current cart.
Required fields:
- card_number: string
- card_exp_month: string
- card_exp_year: string
- card_cvc: string
Requires token header for authentication.
$ curl POST /orders
Required fields:
- id: string
Requires token header for authentication.
$ curl GET /orders?:id
HTTPS is disabled by default.
To use HTTPS, update the add your certificate and private key files to the project and update config.js.