Evolution of a Node.js API, Zoe.js — Project Specification

Adams Academy
4 min readJul 20, 2020

--

The project what we’re going to build is a part of an application, it’s a core module, an ordering system API.

Suppose you have a webshop or basically any kind of application where you can buy products. Ordering is a fundamental module of this application, where you have products and orders. Additionally, this application has users they can be customers or admins.

The project is not complicated, but it’s complex enough to present all the components what I mentioned in the Introduction chapter.

Specification

The purpose of this specification is to give you the description of the Project. This is the place where you can come back time-to-time during the series to know what we build.

Based on the project description you can identify 3 resources:

  • users
  • products
  • orders

Now I’m going through all the resources and show the data structure, the available actions and the relationships. Data structure lists the properties that a resource has and we store it in the database. Available actions are the REST actions on the resources. And we also have relationships between the resources, for example an order has products.

Bird’s eye view

  • Order model has a customer. It’s an ObjectId reference to the User Model.
  • Order model has products. This is not a reference, only a schema connection, we store individual product data to keep the product data snapshot.
  • Order model has productQuantities. This is a Javascript Map type, it stores how many products does an order have.

Users

You can create a user individually.

Data structure

  • usernameString, unique, required — this basically an id
  • passwordString, required
  • roleStringcustomer or admin
{
"username": "adammbalogh",
"password": "password",
"role": "admin"
}

Actions

  • Read users — GET /users - authenticated URI, needs admin role
  • Read a user — GET /users/:id - authenticated URI, customer can read himself, anyway needs admin role
  • Create a user — POST /users - authenticated URI, needs admin role
  • Create a user via CLI

Products

You can create a product individually.

Data structure

  • idString, unique, required
  • nameString, required
  • priceNumber, required — stored in dollar cents, 50000 dollar cents is 500 dollar
{
"id": "PID6112",
"name": "Samsung UE55TU8002 LED TV",
"price": 50000
}

Actions

Everyone can read products but only admins can create, delete or update it (manage).

  • Read products — GET /products - non-authenticated URI
  • Read a product — GET /products/:id - non-authenticated URI
  • Create a product — POST /products - authenticated URI, needs admin role
  • Update a product — PATCH /products/:id - authenticated URI, needs admin role
  • Delete a product — DELETE /products/:id - authenticated URI, needs admin role

Orders

To create an order you need a customer and at least 1 product.

Data structure

  • idString, unique, required
  • amountNumber, required
  • orderedAt - Date - current time by default
  • products - required - products, stored as entire data structure to keep Product history
  • productQuantities - required - stores the quantity for each product
  • customer - required - user model
{
"id": "OID8815",
"products": [
{
"id": "PID6112",
"quantity": 1
},
{
"id": "PID221",
"quantity": 5
}
],
"customerUsername": "adammbalogh"
}

Actions

  • Read orders — GET /orders - authenticated URI, needs admin role
  • Read an order — GET /orders/:id - authenticated URI, customer can read his order, anyway needs admin role
  • Read a product from an order — GET /orders/:id/products/:product_id - authenticated URI, customer can read his order, anyway needs admin role
  • Create an order — POST /orders - authenticated URI, customer can do this, task: send email to customer

--

--

Adams Academy

Adams Academy helps you to cut through the noise and understand programming languages, web development with simple programming tutorials.