API endpoints for teacher booking system
REFT API provides a set of endpoints to manage booking operations, checkout , messages ,halls, and user authentication. This README file outlines the available endpoints, their functionalities, and installation instructions.
- Postgres for the database
- Node/Express for the application logic
- dotenv from npm for managing environment variables
- db-migrate from npm for migrations
- jsonwebtoken from npm for working with JWTs
-
Clone the repository:
Git clone https://github.com/osmanramadan/Backend__Reft__Website.git
-
Configure environment variables:
- Setting up
.env
POSTGRES_HOST ='' PROD_POSTGRES_HOST ='' DEV_FRONT_LINK ='' PROD_FRONT_LINK ='' #Switch Between dev or prod NODE_ENV ='' PORT ='' DEV_POSTGRES_DB ='' PROD_POSTGRES_DB ='' POSTGRES_USER ='' POSTGRES_PASSWORD ='' PROD_POSTGRES_PASSWORD ='' POSTGRES_PORT ='' TOKEN_SECRET ='' JWT_EXPIRES_IN ='' BCRYPT_PASSWORD ='' SALT_ROUNDS ='' # EMAIL SETTINGS EMAIL_HOST ='' EMAIL_PASSWORD ='' EMAIL_PORT ='' #paypal PAYPAL_CLIENT_ID ='' PAYPAL_SECRET ='' PAYPAL_HOME ='' #stripe STRIPE_SECRET_KEY =''
- Setting up
-
Set up database:
- Create database and name it (reft)
- Create new user
CREATE USER reftreft WITH PASSWORD 'reftreft'; - In psql run the following to create the dev and test database
CREATE DATABASE reft;CREATE DATABASE test_reft;
- Connect to the databases and grant all privileges
- Grant for dev database
\c reftGRANT ALL PRIVILEGES ON DATABASE reft TO reftreft;
- Grant for test database
\c test_reftGRANT ALL PRIVILEGES ON DATABASE test_reft TO reftreft;
- Grant for dev database
- Import reft.sql in postgres
-
Install dependencies:
-
Install backend dependencies:
npm install
-
Run the development server:
npm run start
-
- POST
/signup- Create a new user account.
- required inputs:
{ "email": "", "username":"", "password":"", "phone":"", "city":"", "role":"" }
- required inputs:
- Create a new user account.
- POST
/login- Authenticate user credentials.
- required inputs:
{ email="", password="" }
- required inputs:
- Authenticate user credentials.
- POST
/forgotPassword- forgot password endpoint to renew password.
- required inputs:
{ email="" }
- required inputs:
- forgot password endpoint to renew password.
- POST
/verifyResetCode- verify reset code to renew password.
- required inputs:
{ email="", resetCode="" }
- required inputs:
- verify reset code to renew password.
- POST
/resetPassword- reset password and setting new password
- required inputs:
{ email="", newpassword="" }
- required inputs:
- reset password and setting new password
- GET
/verifyuser- Get user info by token and check if JWT period is expired or not (used in frontend to identify the period should user spend in system to login again)
- required inputs :
userid _Coming from token after parsing_
- required inputs :
- Get user info by token and check if JWT period is expired or not (used in frontend to identify the period should user spend in system to login again)
THE REST ENDPOINTS ARE UNUSED
-
GET
/- Get all halls.
-
GET
/cities- Retrieve all cities.
-
GET
/getadminhalls- Retrieve all halls which are unchecked to make admin cofirm it.
-
GET
/:id- Retrieve all halls of specific user.
-
GET
/video/:filename- Retrieve video by its name.
-
GET
/pdf/:filename- Retrieve pdf by its name.
-
POST
/addhall- Add new hall by owner
- required inputs:
{ name="", capacity="", city="", price="", location="", details="", images=[], imageCover="", pdf="", video="", user_id=""
- required inputs:
- Add new hall by owner
-
POST
/delete/:id- Delete hall by its paramter id.
-
POST
/addrate- Add rate to specific hall
- required inputs:
{ hallid="", userid="", rate="" };
- required inputs:
- Add rate to specific hall
-
POST
/hallcodes- get the codes of hall
- required inputs:
{ id="" };
- required inputs:
- get the codes of hall
-
POST
/showrate- show rate of specific hall
- required inputs:
{ hallid="", userid="" };
- required inputs:
- show rate of specific hall
-
PUT
/- Update status of specific hall (only for admin)
- required inputs:
{ checked="", id="" };
- required inputs:
- Update status of specific hall (only for admin)
- GET
/- Get all messages (only for admin)
- required inputs:
{ checked="", id="" };
- required inputs:
- Get all messages (only for admin)
- POST
/- Add new messages
- required inputs:
{ name="", phone="", email="", message="", user_id=""
- required inputs:
- Add new messages
- DELETE
/delete/:id- Delete messages (only for admin)
- POST
/createorderpaypal- Description: Create a new order using the PayPal gateway.
- Required Inputs:
-
{ amount:'' }
-
- POST
/createorderstripe- Description: Create a new order using the Stripe gateway.
- Required Inputs:
-
{ amount:'' }
-
- POST
/capturepaymentpaypal?token=?-
Description: Capture the order using the PayPal gateway. After the token is validated, insert book info into the database.
-
Request Format:
-
The request contains two arrays: one for
dashboardand another forbooktable. -
For type
onehour:-
Dashboard Info:
{ "userid": "", "halluserid": "", "hallid": "", "date": "", "hour": "", "type": "", "amount": "", "secretcode": "generateNumericSecretCode()" } -
Book Table Data:
{ "type": "", "userid": "", "hallid": "", "date": "", "day": "", "hour": "", "year": "", "month": "", "code": "${hallid}${year}${month}${day}${hour}" }
-
-
For type
hourdays:-
Dashboard Info:
{ userid="", halluserid="", hallid="", datefrom="", dateto="", hour="", type="", amount="", secretcode: generateNumericSecretCode() } -
Book Table Data - loop for bookinfo and get the next data-:
{ userid, hallid, date, day, hour, year, month, code }
-
-
For type
dayshours:-
Dashboard Info:
{ userid, halluserid, hallid, datefrom, dateto, hourfrom, hourto, type, amount, secretcode: generateNumericSecretCode() } -
Book Table Data - loop for bookinfo and get the next data-:
{ userid, hallid, date, day, hour, year, month, code }
-
-
-
For type
dayhours:-
Dashboard Info:
{ userid, halluserid, hallid, date, hourfrom, hourto, type, amount, secretcode: generateNumericSecretCode() } -
Book Table Data - loop for bookinfo and get the next data-:
{ userid, hallid, date, day, hour, year, month, code }
-
-
Complete Request Format for onehour:
{ "amount": "", "data": { "dashboardinfo": { // Dashboard info here }, // Other data here } } -
Complete Request Format for other types:
{ "amount": "", "data": { "type":"", "dashboardinfo": { // Dashboard info here }, "bookinfo":{ // Book info here } }
-
- POST
/capturepaymentstripe?sessionid=?- Description capture the order using stripe gateway
- After the process of sessionid validation success insert book info into database same as paypal
- Description capture the order using stripe gateway
-
GET
/- Description: Get booking info of two side(owner,teacher) only for admin.
-
GET
/teacherbooking/:id- Description: Get booking info of teacher
-
GET
/ownerbooking/:id- Description: Get booking info of owner
- Authentication is required for most routes using JWT tokens (
verifymiddleware).
For questions or feedback,, contact Me at osmanramadan840@gmail.com