POST /sign-up
{
name: String, at least 3 letters,
email: String, at least 5 letters, must include @ and .something at the end,
password: String, at least 8 letters, no differentiation between upper and lower cases,
}None, this is a public route- 400: You have forgotten to send something, or sent invalid data, check your parameters
- 409: This e-mail is already registered
- 201: Account createdPOST /sign-in
{
email: 'User email',
password: 'User password',
}None, this is a public route- 400: You have forgotten to send something, or sent invalid data, check your parameters
- 404: This e-mail is not registered
- 401: Incorrect password
- 200: Logged In{
token: JWT,
name: username,
}POST /subscribe
{
plan: String, must be either "monthly" or "weekly",
deliveryDate: String, must be "01", "10" or "20" if plan is "monthly", otherwise, must be "monday", "wednesday" or "friday",
itemsWanted: Array, must include only numbers 1 to 3,
zipcode: String, must be 8 letters long and include only numbers
number: Number, is the house number
}{
headers: {
'x-access-token': JWT
}
}- 400: You have forgotten to send something, or sent invalid data, check your parameters
- 409: This account already has a subscription, check PUT method on this route
- 401: Your JWT is invalid
- 201: Subscribed{
newToken: JWT, if needed, further explanations on persistent login section
}PUT /subscribe
{
plan: String, must be either "monthly" or "weekly",
deliveryDate: String, must be "01", "10" or "20" if plan is "monthly", otherwise, must be "monday", "wednesday" or "friday",
itemsWanted: Array, must include only numbers 1 to 3,
zipcode: String, must be 8 letters long and include only numbers
number: Number, is the house number
}{
headers: {
'x-access-token': JWT
}
}- 400: You have forgotten to send something, or sent invalid data, check your parameters, or you dont have a subscription yet
- 401: Your JWT is invalid
- 200: Subscription changed{
newToken: JWT, if needed, further explanations on persistent login section
}GET /user-subscription
{
headers: {
'x-access-token': JWT
}
}- 401: Your JWT is invalid
- 200: Everything ok{
subscriptionId: String, will be either 1, meaning 'monthly' or 2, meaning 'weekly',
newToken: JWT, if needed, further explanations on persistent login section
}GET /user-info
{
headers: {
'x-access-token': JWT
}
}- 401: Your JWT is invalid
- 200: Everything ok{
subscriptionName: String, will be either 'monthly' or 'weekly',
subscriptionDate: String, will be on 'DD/MM/YYYY' format,
wantedItems: Array, only numbers from 1 to 3,
dates: Array, will have 3 dates on 'DD/MM/YYYY' format,
newToken: JWT, if needed, further explanations on persistent login section
}POST /feedback
{
boxId: Number, must be a valid deliveryId,
feedbackId: Number, must be 1 for positive or 2 for negative,
comment: String, must not be sent if feedbackId is 1, otherwise, must have at least 8 characters
}{
headers: {
'x-access-token': JWT
}
}- 400: You have forgotten to send something, or sent invalid data, check your parameters
- 403: Your boxId does not match your userId or you already rated this delivery
- 401: Your JWT is invalid
- 200: Feedback received{
newToken: JWT, if needed, further explanations on persistent login section
}GET /delivered-boxes
{
headers: {
'x-access-token': JWT
}
}- 401: Your JWT is invalid
- 200: Everything ok{
dates: Array, will contain every box you have ever received, on the 'DD/MM/YYYY' format,
newToken: JWT, if needed, further explanations on persistent login section
}GET /update-boxes
{
headers: {
'x-access-token': JWT
}
}- 401: Your JWT is invalid
- 200: Everything ok{
newToken: JWT, if needed, further explanations on persistent login section
}POST /persist-login
{
token: JWT,
}None- 401: Your JWT is invalid
- 200: Everything ok{
newToken: JWT;
}# Every private route requests the JWT given to you at some point
# Thats because only logged users should be able to make those requests on the database
# Every JWT is valid for 15 minutes, after that, every private route you access would return 401 (unauthorized)
# To avoid user frustration, when the JWT is expired, every route also checks if the token is exactly the last one registered in the database
# If it is, the access is granted one more time, and a new token is given to the user
# That why every private route can give you a newTokengit clone https://github.com/bruch0/gratibox-API.git
cd gratibox-API
npm i --force
Create a .env.dev file and fill it using your environment variables following this example
sudo su postgres
psql
CREATE DATABASE gratibox
\c gratibox
Copy everything in the dump.sql file and paste on the terminal
You can not exit the postgres admin, and run
npm run start:dev
Create a .env.test file and fill it using your environment variables following this example
sudo su postgres
psql
CREATE DATABASE gratibox_test;
\c gratibox_test
Copy everything in the dump.sql file and paste on the terminal
You can not exit the postgres admin, and run
npm run test
You can check the server running on heroku here!