Welcome to my 4th project for GeeksHub Academy and my first backend project.
Summary 📝
This project required a functional API connected to a database with at least a one-to-many relationship and a many-to-many relationship.
As tables that dont depend of others we've got service, that is just a table with the id, name of service an a description of the service we offer and role that show the id of the role and the name of that role.
Next we have the table users which is related to role and appointment. The relation consist in every user has a role, which currently can be super_admin, artist or user (the default one).
Appointment table has two foreign key, both are from user_id, in client_id column we have users with role user or roleId 3 and in artist_id column just can be there user whose role are 1 or 2 (I'm assuming the owner of the shop or super_admin is also an artist).
- Clone the repository
git clone https://github.com/FornesBorja/tatooStudioBackend.git
- Open the folder
$ npm i
- Copy the .env.example file, change the name of the copy to .env.
- Write the .env file with your server parameters, to make the server work.
$ npm run migrate
$ npm run seed
$ npm run dev
Auth
-
REGISTER
-
BY DEFAULT IS USER.
POST https://tattoo-studio-fornesb.zeabur.app/api/auth/register
Body:
{ "firstName":"Pepe", "email":"[email protected]", "password":"123456789" }
-
-
LOGIN
-
IT WILL RETURN A TOKEN.
POST http://localhost:4000/api/auth/login
Body:
{ "email":"[email protected]", "password":"Pass1234!" }
-
Users
-
GET ALL USERS (SUPER_ADMIN)
-
ONLY SUPER_ADMIN IS ALLOWED TO ACCESS TO THIS ENDPOINT
Auth:
``` bearer { eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY } ```
This token is just an example, it doesn't work.
-
-
GET USER PROFILE
-
ONLY THE USER IS ALLOWED TO DO THIS ENDPOINT
GET https://tattoo-studio-fornesb.zeabur.app/api/users/profile
Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY }
This token is just an example, it doesn't work.
-
-
EDIT USER PROFILE
- USER CAN EDIT ITS ALL THEIR INFO EXCEPT ROLE.
PUT https://tattoo-studio-fornesb.zeabur.app/api/users/profile
Body:
{ "email":"[email protected]", }
In the body, the fields you want to edit are placed. Here is an example.
Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY }
This token is just an example, it doesn't work.
-
FILTER BY EMAIL (SUPER_ADMIN)
- ONLY ACCESSIBLE BY SUPER_ADMIN
GET https://tattoo-studio-fornesb.zeabur.app/api/[email protected]
Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY }
This token is just an example, it doesn't work.
-
DELETE USER (SUPER_ADMIN)
- ONLY ACCESSIBLE BY SUPER_ADMIN
DELETE https://tattoo-studio-fornesb.zeabur.app/api/users/1
Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY }
This token is just an example, it doesn't work.
I added delete on cascade to make it work, if not it will throw an error because user_id is foreing key (2 times) in appointment table. -
UPDATE USER ROLE(SUPER_ADMIN)
- ONLY ACCESSIBLE BY SUPER_ADMIN
PUT https://tattoo-studio-fornesb.zeabur.app/api/users/1/role
Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJob2xhQGhvbGEuYWRpb3MiLCJpYXQiOjE3MjA1OTYyNzMsImV4cCI6MTcyMDYwMzQ3M30.QnL_HgGPVLOb0d4iUUuFCeSab1lp3SpOVV_js0T4ExY }
This token is just an example, it doesn't work.
Body:
{ "roleId": 2 }
We have to just type the roleId we want, no other column will be update, just the role.
Appointments
-
CREATE APPOINTMENT
-
A USER CAN CREATE AN APPOINTMENT
POST https://tattoo-studio-fornesb.zeabur.app/api/appointments
Auth:
``` bearer { eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s } ```
Body:
``` json { "date":"27/07/2024", "hour": "18:04", "artistId":8, "serviceId":2 } ```
You will get an error if the entered date is earlier than the current date or if the artistId is not role 1 or 2 (super_admin or artist) or if theres already booked an appointment for that artist and a certain time.
-
-
UPDATE APPOINTMENT
-
A USER CAN UPDATE THEIR APPOINTMENT
PUT https://tattoo-studio-fornesb.zeabur.app/api/appointments
Auth:
``` bearer { eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s } ```
This token is just an example, it doesn't work.
Body:
``` json { "id":6, "serviceId":1 } ```
Id of the appointment is mandatory, the other options are optional.
-
-
GET ALL APPOINTMENTS
-
A USER CAN SEE ALL THEIR APPOINTMENTS AND ITS INFO
GET https://tattoo-studio-fornesb.zeabur.app/api/appointments
Auth:
``` bearer { eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s } ``` This token is just an example, it doesn't work. It will also show extra infor like your client (your own) and artist email, first name and service name
-
-
GET APPOINTMENT BY ID
-
A USER CAN SEE AN APPOINTMENT AND ITS INFO BY THE ID THEY PICKED
GET https://tattoo-studio-fornesb.zeabur.app/api/appointments/6
Auth:
``` bearer { eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s } ```
This token is just an example, it doesn't work. The 6 in the endpoint is just an example of id, you can put the id you want your user have access to.
It will also show extra infor like your client (your own) and artist email, first name and service name
-
Services
-
GET ALL SERVICES
-
EVERYONE EVEN IF IT'S NOT LOGGED CAN RETRIEVE ALL SERVICES AND CONSULTING THEM
-
-
CREATE SERVICES (SUPER_ADMIN)
-
ONLY SUPER_ADMIN CAN CREATE A SERVICE
POST https://tattoo-studio-fornesb.zeabur.app/api/services Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s }
Body:
``` json { "serviceName": "Printed ilustrations", "description": "Printed illustrations of the designs that you can later tattoo" } ```
-
-
UPDATE SERVICES (SUPER_ADMIN)
-
ONLY SUPER_ADMIN CAN UPDATE A SERVICE
PUT https://tattoo-studio-fornesb.zeabur.app/api/services/2 Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s }
Body:
``` json { "serviceName": "Piercing jewelry", } ```
-
-
DELETE SERVICES (SUPER_ADMIN)
-
ONLY SUPER_ADMIN CAN DELETE A SERVICE
DELETE https://tattoo-studio-fornesb.zeabur.app/api/services/2 Auth:
{ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiZW1haWwiOiJtYXJpYS5nYXJjaWFAZXhhbXBsZS5jb20iLCJpYXQiOjE3MjA4ODI3MDQsImV4cCI6MTcyMDg4OTkwNH0.CiQ7BQoE6PEUOHkneg3GBEhe_QXbVc5lgkVQmK9La_s }
-
✅ More endpoints with more features
🔲 Being able to choose your artist
✅ Appointment date validation, preventing scheduling of appointments with dates earlier than the current date
✅ Validations to make sure the integrity of the database
- Esperanza Fornes - student Full Stack Developer Web