Skip to content

Instantly share code, notes, and snippets.

@SimonJinaphant
Last active April 3, 2019 00:29
Show Gist options
  • Save SimonJinaphant/fa997f4c404cb1cf891f77ce8db13b6d to your computer and use it in GitHub Desktop.
Save SimonJinaphant/fa997f4c404cb1cf891f77ce8db13b6d to your computer and use it in GitHub Desktop.
Capstone

Setting up the Fake SQL backend

Perform the following commands in your Terminal or Git Bash

git clone https://gitlab.com/benk9/cpen491.git backendServer

cd backendServer/backend

git checkout mobile-fake-sql

npm install

Key Points for using Fake SQL

  • /GET routes have hard-coded data

  • /POST and /PATCH routes simply console.log() whatever the HTTP request body contained.

  • /POST endpoints also return an id hardcoded to 123. You should save these ID on the mobile client as they represent your "key" to make/change future requests.

  • If you attempt to hit any endpoint with an improperly formatted JSON payload in the body, or an improper URL parameter, it will reject it and tell you why in the HTTP response payload.

  • You can view all the available routes in restaurant.controller.ts and the hard-coded data in sql-stored-procedure-fake.service.ts.

Starting point

Once the customer taps the NFC, you can start a session by performing a

/POST to http://localhost:3001/restaurants/1/sessions with the following payload

{
    tableNumber: 85
}

Get all restaurant categories

Perform a /GET to http://localhost:3001/restaurants/1/categories

Get all products in a category

Perform a /GET to http://localhost:3001/restaurants/1/categories/1/products

  • In this version of Fake SQL: Supplying a category ID between 1 and 10 returns different categories :) Any other ID will return an empty list

Get all options for a product

Perform a /GET to http://localhost:3001/restaurants/1/categories/10/products/57/options

  • Only product ID 57 return options, all other product ID will return empty list signifying there are no customizable options

Submit an order

Perform a /POST to http://localhost:3001/restaurants/1/sessions/123/orders with the following payload:

{
    tableNumber: 85,
    category: "MyCategory",
    product: "MyProduct",
    options: "",
    finalProductPrice: 14.99,
    comments: null
}
  • Note: Ideally we should be submitting the IDs instead of the names for the category, product, options, and let the backend compute the actual finalProductPrice; but we're short on time so we'll blindly trust the mobile requests.

Add yourself onto a waitlist

Perform a /POST to http://localhost:3001/restaurants/1/waitlist with the following payload:

{
    phone: "604-123-4567",
    name: "John Doe", 
    seatRequest: 3
}

Submit an assistance request

Perform a /POST to http://localhost:3001/restaurants/1/sessions/123/assist with the following payload:

{
    tableNumber: 85
}

Cancel an order

Perform a /PATCH to http://localhost:3001/restaurants/1/sessions/123/orders/123 with the following payload:

{
    requestState: 2
}

Cancel an assistance request

Perform a /PATCH to http://localhost:3001/restaurants/1/sessions/123/assist/123 with the following payload:

{
    requestState: 2
}

Cancel a waitlist

Perform a /PATCH to http://localhost:3001/restaurants/1/waitlist/123 with the following payload:

{
    requestState: 2
}

Ending the session (a.k.a. Requesting the bill at the restaurant)

Perform a /PATCH to http://localhost:3001/restaurants/1/sessions/123 with the following payload:

{
    sessionState: 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment