All queries are returning a promise where I check the completion and failure for each scenario.
There are 3 tables (7 in development) at the moment.
grocery_list
: id(primary key), name(text), is_completed(boolean)tag-list
: id(primary key), name(text), rank(real), bg_color(text), text_color(text)grocery_tag_junction
: junction table, grocery_id(foreign key), tag_id(foreign key)
The DATABASE_URL
or SHOPPING_LIST_DATABASE_URL
environment variable is expected to
be set to a PostgreSQL connection string. The former is used by fly.io
, the later is
connivent for development. Best to set up SHOPPING_LIST_DATABASE_URL
in your .profile
or similar.
See database/database.js
.
To connect with PgAdmin, enter the following to command line:
fly proxy 5432 -a galexdb
POST
: adds the new grocery list item to the database.
- back-end receives object with
name
andis_completed
; - checks if
req.body
hasis_completed
in it, if not then add to it; - checks all the data types, if any is not a match, then returns 405 status;
- if an error occurs in the server, return 500 status.
PUT
: updates the selected grocery_list name, and complete status.
- back-end receives object with
name
,id
,is_completed
; - checks if
req.body
hasis_completed
in it, If not then add to it; - checks all the data types, if any is not a match, then returns 405 status;
- back-end receives
id
; - converts
param.id
to Number; - checks if
param.id
is not a number, returns 400 status; - returns 204 if successful, if
param.id
doesn't exist, then 404 status; - otherwise, if an error occurs in the server, it returns 500 status;
- back-end receives a query for
is_completed
status; - checks if
req.body.is_completed
exists in thereq.body
, if not then an empty string""
is added to the var; - checks each scenario if we wish to send back the completed, not completed, all status
is_completed
shop items; - if an error occurs in server, returns a 500 status;
- else, calls
sendResults
function which will change any null value to an empty array, and sends 200 status;
GET
: returns the tag list items to the front-end, therefore the user can choose which tag to add to a grocery item;
- query is written by @igalex
- checks if the query has any result;
- if yes, returns the query with 200 status;
- if server error occurs, returns 500 status;
- if the query is falsy, returns 404 status;
POST
: posts to grocery_tag_junction
:
- back-end receives the selected
grocery_id
andtag_id
; - checks if req.body contains the correct data types, else it returns 405 status;
- if promise is fulfilled, returns 201 status;
- if an error occurs in the server, returns 500 status;
DELETE
: deletes the selected row from grocery_tag_junction
:
- back-end receives the selected
grocery_id
andtag_id
; - converts
grocery_id
andtag_id
to Number; - if any is not a number, then returns 400 status;
- after promise, if fulfilled, checks if any value exist, if not then returns 404 status;
- else sends 204 status;
- if server error occurs, returns 500 status;