Skip to content

Clovis-krz/api.ieumy.com

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api.ieumy.com

Author: Clovis Krzyzanowski

Ieumy is a website to order and pay food in a restaurant from a QR code, don't wait to order ! api.ieumy.com is the backend part of the App, composed of an API.

Unfinished project ended in september 2022

Tools:

Technologies :

  • Node JS
  • postgresql

Libraries :

  • Express
  • pg (posgresql)
  • bcrypt
  • JsonWebToken

Lauch the App :

Clone the repository :

$ git clone ssh://[email protected]:9010/clovis/api.ieumy.com.git

Enter the repository :

$ cd api.ieumy.com

Create an image folder :

$ mkdir images

Enter the images repository :

$ cd images

Create an item directory :

$ mkdir items

Create a restaurant directory :

$ mkdir restaurants

Go back to the root of the repository :

$ cd ..

Launch the server :

$ node server

ROUTES:

Restaurants routes :

Get a Restaurant (customers and not authentificated, restaurant need an attached subscription) :

GET http://localhost:3000/api/restaurants?id=[restaurant-id]&table_nb=[table-nb]

Get my Restaurant (owners) :

GET http://localhost:3000/api/restaurants/my

with headers :

{
    "authorization": [jwt token],
}

Get stripe_account link for my Restaurant (owners, need a subscription) :

GET http://localhost:3000/api/restaurants/my/stripe-account

with body :

{
    "restaurant": [restaurant_id],
}

and headers :

{
    "authorization": [jwt token],
}

Create a Restaurant (owners) :

POST http://localhost:3000/api/restaurants

with body :

{
    "name": "",
    "description": "",
    "image": [restaurant image file],
}

and headers :

{
    "authorization": [jwt token],
}

Update my Restaurant (owners, need a subscription) :

PUT http://localhost:3000/api/restaurants

with body :

{
    "restaurant": [resto_id],
    "name": "",
    "description": "",
    "image": [restaurant image file] (if no image update then forget this field),
}

and headers :

{
    "authorization": [jwt token],
}

Update my Menu (owners, need a subscription) :

PUT http://localhost:3000/api/restaurants/menu

with body :

{
    "restaurant": [resto_id],
    "categories": "",
}

and headers :

{
    "authorization": [jwt token],
}

Add category to Menu (owners, need a subscription) :

POST http://localhost:3000/api/restaurants/menu/category

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name]
}

and headers :

{
    "authorization": [jwt token],
}

Rename a category in Menu (owners, need a subscription) :

PUT http://localhost:3000/api/restaurants/menu/category

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "new_category_name": [new_category_name]
}

and headers :

{
    "authorization": [jwt token],
}

Delete a category from Menu (owners, need a subscription) :

DELETE http://localhost:3000/api/restaurants/menu/category

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name]
}

and headers :

{
    "authorization": [jwt token],
}

Add item to Menu (owners, need a subscription) :

POST http://localhost:3000/api/restaurants/menu/item

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "name": [item_name],
    "description": [item_description],
    "price": [item_price],
    "image": [item_image (file)]
}

and headers :

{
    "authorization": [jwt token],
}

Update item in Menu (owners, need a subscription) :

PUT http://localhost:3000/api/restaurants/menu/item

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "id": [item_id],
    "name": [item_name],
    "description": [item_description],
    "price": [item_price],
    "image": [item_image (file)] (only if update picture otherwise no image field)
}

and headers :

{
    "authorization": [jwt token],
}

Delete item from Menu (owners, need a subscription) :

DELETE http://localhost:3000/api/restaurants/menu/item

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "id": [item_id]
}

and headers :

{
    "authorization": [jwt token],
}

Add Variation to item in Menu (owners, need a subscription) :

POST http://localhost:3000/api/restaurants/menu/item/variation

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "item_id": [item_id],
    "name": [item_name],
    "price_delta": [price_delta with original item]
}

and headers :

{
    "authorization": [jwt token],
}

Update Variation item in Menu (owners, need a subscription) :

PUT http://localhost:3000/api/restaurants/menu/item/variation

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "item_id": [item_id],
    "name": [current item_name],
    "new_name": [new item_name],
    "price_delta": [new price_delta with original item]
}

and headers :

{
    "authorization": [jwt token],
}

Delete Variation item from Menu (owners, need a subscription) :

DELETE http://localhost:3000/api/restaurants/menu/item/variation

with body :

{
    "restaurant": [resto_id],
    "category_name": [category_name],
    "item_id": [item_id],
    "name": [item_name],
}

and headers :

{
    "authorization": [jwt token],
}

Owners routes :

Register :

POST http://localhost:3000/api/owners

with body :

{
    "email": "",
    "firstname": "",
    "lastname": "",
    "password": ""
}

Confirm Account :

GET http://localhost:3000/api/owners/confirm-account?token=[token]

Login :

POST http://localhost:3000/api/owners/login

with body :

{
    "email": "",
    "password": ""
}

Update (lastname, firstname) :

PUT http://localhost:3000/api/owners

with body :

{
    "firstname": "",
    "lastname": "",
}

and headers :

{
    "authorization": [jwt token],
}

Update password :

PUT http://localhost:3000/api/owners/password

with body :

{
    "email": "",
    "password": "",
    "new_password": [new_password]
}

Update email :

PUT http://localhost:3000/api/owners/email

with body :

{
    "new_email": [new_email_address]
}

and headers :

{
    "authorization": [jwt token],
}

Confirm Update email :

GET http://localhost:3000/api/owners/confirm-email?token=[token]

Delete :

Also delete restaurant, orders and subcriptions

DELETE http://localhost:3000/api/owners

with headers :

{
    "authorization": [jwt token],
}

Customers routes :

Register :

POST http://localhost:3000/api/customers

with body :

{
    "email": "",
    "firstname": "",
    "lastname": "",
    "password": "",
    "address": ""
}

Confirm Account :

GET http://localhost:3000/api/customers/confirm-account?token=[token]

Login :

POST http://localhost:3000/api/customers/login

with body :

{
    "email": "",
    "password": ""
}

Update (lastname, firstname, address) :

PUT http://localhost:3000/api/customers

with body :

{
    "firstname": "",
    "lastname": "",
    "address": ""
}

and headers :

{
    "authorization": [jwt token],
}

Update password :

PUT http://localhost:3000/api/customers/password

with body :

{
    "email": "",
    "password": "",
    "new_password": ""
}

Update email :

PUT http://localhost:3000/api/customers/email

with body :

{
    "new_email": [new_email]
}

and headers :

{
    "authorization": [jwt token]
}

Confirm update email :

GET http://localhost:3000/api/customers/confirm-email?token=[token]

Delete :

DELETE http://localhost:3000/api/customers

with headers :

{
    "authorization": [jwt token]
}

Orders routes :

an order status is either : "pending", "payed", "served" or "cancelled" when order is served or cancelled, it is not possible to update is anymore and a end_time is given. An order will never be visible by the restaurant owner as long as the order is not at least payed. The pending status is only visible for the backend to handle the payment processing. An order that not payed within an hour is automatically deleted from the database.

Create an order :

POST http://localhost:3000/api/orders

with body :

{
    "lastname": "", //only for logged out customers
    "firstname": "", //only for logged out customers
    "email": "", //only for logged out customers
    "items": [item],
    "resto_id": [restaurant_id],
    "table_nb": [table_nb]
}

and headers (optional: only for logged in customers) :

{
    "authorization": [jwt token],
}

item example (without variation) :

{
    "id": 0,
    "name": "Oeuf mimosa",
    "variation": null,
    "price": 4,
    "qty": 11
}

item example (with variation) :

{
    "id": 7,
    "name": "Choux chantilly",
    "description": "magnifique choux chantilly préparé par un vrai chef",
    "variation": {
        "name": "nappage choco",
        "price_delta": 0.5
    },
    "qty": 1
}

Get my order (for customers) :

GET http://localhost:3000/api/orders/my

with body :

{
    "restaurant": [restaurant_id],
    "id": [order_id]
}

Get orders ("payed", "served" or "cancelled") (for restaurant owners and employees) :

GET http://localhost:3000/api/orders

with body :

{
    "restaurant": [restaurant_id]
}

and headers :

{
    "authorization": [jwt token],
}

Get payed orders (for restaurant owners and employees) :

GET http://localhost:3000/api/orders/payed

with body :

{
    "restaurant": [restaurant_id]
}

and headers :

{
    "authorization": [jwt token],
}

Update order to served :

PUT http://localhost:3000/api/orders/update/served

with body :

{
    "restaurant": [restaurant_id],
    "order_id": ""
}

and headers :

{
    "authorization": [jwt token],
}

Update order to cancelled :

PUT http://localhost:3000/api/orders/update/cancelled

with body :

{
    "restaurant": [restaurant_id],
    "order_id": ""
}

and headers :

{
    "authorization": [jwt token],
}

Subscriptions routes :

Get Actual subscription (for owners) :

GET http://localhost:3000/api/subscriptions/current

with body :

{
    "restaurant": [restaurant_id]
}

and headers :

{
    "authorization": [jwt token],
}

Create a new subscription (for owners) :

POST http://localhost:3000/api/subscriptions/new

with body :

{
    "restaurant": [restaurant_id],
    "table_amount": [number of tables in subscription]
}

and headers :

{
    "authorization": [jwt token],
}

Get Portal link to manage subscriptions (for owners) :

GET http://localhost:3000/api/subscriptions/manage-link

with headers :

{
    "authorization": [jwt token],
}

Webhooks a (for stripe) :

Update Payment status (to payed or failed) : if payed then updates in database and becomes visible for restaurant owner otherwise if failed then the order is deleted from the database

POST http://localhost:3000/api/webhooks/stripe/payment-status

Update Subscription Payment status (to pending or payed): if payed then subscription becomes active for 30 days, otherwise subscription is not active. Renew Subscription when paid: when triggered take last active subscription of owner and renew it for 30 days. Send Email to owner when subscription payment failed and warn that after the deadline, service won't be provided anymore

POST http://localhost:3000/api/webhooks/stripe/subscription-status

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published