Skip to content

Latest commit

 

History

History
398 lines (282 loc) · 12.1 KB

README.md

File metadata and controls

398 lines (282 loc) · 12.1 KB

Tattoo Studio

Welcome to my 4th project for GeeksHub Academy and my first backend project.

LineInk Tattoo Studio

Summary 📝
  1. Objective
  2. Deploy
  3. Stack
  4. DB Scheme
  5. Installation
  6. Endpoints
  7. Futures functionalities and things to improve
  8. Author

Objective

This project required a functional API connected to a database with at least a one-to-many relationship and a many-to-many relationship.

Deploy

Stack

DB Scheme

DB-Scheme 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).

Local installation

  1. Clone the repository git clone https://github.com/FornesBorja/tatooStudioBackend.git
  2. Open the folder
  3. $ npm i
  4. Copy the .env.example file, change the name of the copy to .env.
  5. Write the .env file with your server parameters, to make the server work.
  6. $ npm run migrate
  7. $ npm run seed
  8. $ npm run dev

Endpoints

Auth
Users
  • GET ALL USERS (SUPER_ADMIN)

    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

    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

    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

    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

    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

  • 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
          }
      

Futures functionalities and things to improve

✅ 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

Author

  • Esperanza Fornes - student Full Stack Developer Web