Before you start make sure you have installed:
- NodeJS that includes
npm
- PostgreSQL
Before using the api for the first time:
- Create the .env file
- Install the dependencies
- Create the needed tables in your database
- Insert the timeslots of table reservation to the database
- Insert the tables of the restaurant to the database
How to create the .env file:
- Create a new file in the root folder and name it: '.env'
- Write the environment variables of your environment as the following format
DB_HOST=[your DBMS host address]
DB_PORT=[your DBMS port]
DB_USER=[database username]
DB_NAME=[database name]
DB_PASSWORD=[database password]
SERVER_PORT=[backend server port]
Example:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_NAME=postgres
DB_PASSWORD=000000
SERVER_PORT=3000
- Save the file
How to install the dependencies:
- Run the following command
npm install
How to create the needed tables in your database:
- Run the following queries in your RDBMS
CREATE TABLE employees (employee_id serial PRIMARY KEY, employee_number INT UNIQUE NOT NULL,employee_name VARCHAR ( 50 ) NOT NULL, password VARCHAR ( 128 ) NOT NULL);
CREATE TABLE reservation_timeslots (reservation_timeslot_id serial PRIMARY KEY, start_at TIME NOT NULL, end_at TIME NOT NULL);
CREATE TABLE tables (table_id serial PRIMARY KEY, number_of_chairs INT NOT NULL, is_active bool NOT NULL);
CREATE TABLE reservations (reservation_id serial PRIMARY KEY, reservation_timeslot_id INT NOT NULL, table_id INT NOT NULL, reservation_date DATE NOT NULL);
Note: SQL file is included
How to insert the timeslots of table reservation to the database:
- Run the following query in your RDBMS to insert reservation timeslot
INSERT INTO reservation_timeslots (start_at, end_at) VALUES ([TIME value], [TIME value]);
Example:
INSERT INTO reservation_timeslots (start_at, end_at) VALUES ('12:30', '13:45');
How to insert the tables of the restaurant to the database:
- Run the following query in your RDBMS to insert reservation timeslot
INSERT INTO tables (number_of_chairs, is_active) VALUES ([INT value], [BOOLEAN value]);
Example:
INSERT INTO tables (number_of_chairs, is_active) VALUES (4, 'true');
API functions
- /login
- /signup
- /check_timeslotes
- /new_reservation
- /get_reservation
- /delete_reservation
/login
/signup
/check_timeslotes
/new_reservation
- Function type: post
- Function parameters: token, reservation_timeslot_id, table_id
- return: success / fail
/get_reservation
- Function type: get
- Function parameters: token, page_number (page of results), is_ascending ('true' or 'false')
- return: a page of reservations data of today that sorted ascending or descending that has up to 10 results, hasNextPage (a bool that showes if their is a next page pf results)
/delete_reservation
- Function type: delete
- Function parameters: token, reservation_id
- return: 'success' / 'no such data reservation'