ThVinicius / repoProvas_backEnd

Home Page:https://repo-provas.fly.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

projeto20-repoProvas

Project developed using TypeScript for tests management

RepoProvas

Built With


Links

Front-end Repository

Deploy Front-end

Deploy Back-end


Description

RepoProvas is a system for sharing tests between students. In RepoProvas, anyone can search for old tests of their disciplines and teachers or send old tests


Features

  • Create accounts and access them
  • List the tests grouped by disciplines
  • List tests grouped by teachers
  • Register tests

API Reference

Authentication routes

Create an account

POST /signup

Request:

Params Type Description
email string Required, email format
password string Required, size equal to or greater than 3
confirmPassword string Required, same as password

Response:

Error cases:

Status code Cause
400 Request in wrong format
409 try to register with an email already registered

Success case (status code 201)

Access to an account

POST /signin

Request:

Params Type Description
email string Required, email format
password string Required, size equal to or greater than 3

Response:

Error cases:

Status code Cause
400 Email and/or password in incorrect format
401 Incorrect email and/or password

Success case (status code 200:)

token: // json web token

Tests routes

Send test

POST /tests

Request:

Send via a multipart/form-data form

Params Type Description
name string required, trim
file application/pdf required
categoryId number required, greater than 0, integer
teacherDisciplineId number required, greater than 0, integer

Headers:

Send the token (Bearer token)
Params Type Description
Authorization string required, Starting with Bearer

Response:

Error cases:

Status code Cause
400 Request in wrong format
401 Invalid token
404 disciplineId and/or teacherDisciplineId does not exist
426 Outdated token
498 Expired token

Success case (status code 201:)

{
  "id": 14,
  "name": "2022 - globo.com",
  "pdfUrl": "https://tpkkzyvybeoysawyhkyc.supabase.co/storage/v1/object/public/pdf-tests/test.pdf",
  "categoryId": 1,
  "teacherDisciplineId": 1,
  "createdAt": "2022-09-18T13:49:07.612Z"
}

Search for tests grouped into disciplines

GET /tests/disciplines

Request:

Headers:

Send the token (Bearer token)
Params Type Description
Authorization string required, Starting with Bearer

Response:

Error cases:

Status code Cause
400 Request in wrong format
401 Invalid token
426 Outdated token
498 Expired token

Success case (status code 200:)

[
  {
    "termId": 1,
    "number": 1,
    "disciplines": [
      {
        "disciplineId": 4,
        "discipline": "Humildade",
        "categories": []
      },
      {
        "disciplineId": 1,
        "discipline": "HTML e CSS",
        "categories": [
          {
            "categoryId": 1,
            "category": "Projeto",
            "tests": [
              {
                "testId": 10,
                "test": "2022 - teste1",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              },
              {
                "testId": 14,
                "test": "2022 - globo.com",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              },
              {
                "testId": 1,
                "test": "prova muito dificil",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              }
            ]
          },
          {
            "categoryId": 2,
            "category": "Prática",
            "tests": [
              {
                "testId": 2,
                "test": "prova muito facil",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              },
              {
                "testId": 3,
                "test": "prova muito media",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "termId": 2,
    "number": 2,
    "disciplines": [
      {
        "disciplineId": 2,
        "discipline": "JavaScript",
        "categories": [
          {
            "categoryId": 2,
            "category": "Prática",
            "tests": [
              {
                "testId": 11,
                "test": "2022 - teste2",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              }
            ]
          }
        ]
      },
      {
        "disciplineId": 5,
        "discipline": "Planejamento",
        "categories": [
          {
            "categoryId": 2,
            "category": "Prática",
            "tests": [
              {
                "testId": 8,
                "test": "teste",
                "pdfUrl": "https://google.com",
                "teacherId": 2,
                "teacher": "Bruna Hamori"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "termId": 3,
    "number": 3,
    "disciplines": [
      {
        "disciplineId": 3,
        "discipline": "React",
        "categories": [
          {
            "categoryId": 1,
            "category": "Projeto",
            "tests": [
              {
                "testId": 9,
                "test": "2022 - TrackIt",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              }
            ]
          },
          {
            "categoryId": 3,
            "category": "Recuperação",
            "tests": [
              {
                "testId": 12,
                "test": "2022 - teste3",
                "pdfUrl": "https://google.com",
                "teacherId": 1,
                "teacher": "Diego Pinho"
              }
            ]
          }
        ]
      },
      {
        "disciplineId": 6,
        "discipline": "Autoconfiança",
        "categories": []
      }
    ]
  },
  {
    "termId": 4,
    "number": 4,
    "disciplines": []
  },
  {
    "termId": 5,
    "number": 5,
    "disciplines": []
  },
  {
    "termId": 6,
    "number": 6,
    "disciplines": []
  }
]

Search for tests grouped into teachers

GET /tests/teachers

Request:

Headers:

Send the token (Bearer token)
Params Type Description
Authorization string required, Starting with Bearer

Response:

Error cases:

Status code Cause
400 Request in wrong format
401 Invalid token
426 Outdated token
498 Expired token

Success case (status code 200:)

[
  {
    "teacherId": 1,
    "teacher": "Diego Pinho",
    "categories": [
      {
        "categoryId": 1,
        "category": "Projeto",
        "tests": [
          {
            "testId": 1,
            "test": "prova muito dificil",
            "pdfUrl": "https://google.com",
            "discipline": "HTML e CSS"
          },
          {
            "testId": 9,
            "test": "2022 - TrackIt",
            "pdfUrl": "https://google.com",
            "discipline": "React"
          },
          {
            "testId": 10,
            "test": "2022 - teste1",
            "pdfUrl": "https://google.com",
            "discipline": "HTML e CSS"
          },
          {
            "testId": 14,
            "test": "2022 - globo.com",
            "pdfUrl": "https://google.com",
            "discipline": "HTML e CSS"
          }
        ]
      },
      {
        "categoryId": 2,
        "category": "Prática",
        "tests": [
          {
            "testId": 2,
            "test": "prova muito facil",
            "pdfUrl": "https://google.com",
            "discipline": "HTML e CSS"
          },
          {
            "testId": 3,
            "test": "prova muito media",
            "pdfUrl": "https://google.com",
            "discipline": "HTML e CSS"
          },
          {
            "testId": 11,
            "test": "2022 - teste2",
            "pdfUrl": "https://google.com",
            "discipline": "JavaScript"
          }
        ]
      },
      {
        "categoryId": 3,
        "category": "Recuperação",
        "tests": [
          {
            "testId": 12,
            "test": "2022 - teste3",
            "pdfUrl": "https://google.com",
            "discipline": "React"
          }
        ]
      }
    ]
  },
  {
    "teacherId": 2,
    "teacher": "Bruna Hamori",
    "categories": [
      {
        "categoryId": 2,
        "category": "Prática",
        "tests": [
          {
            "testId": 8,
            "test": "teste",
            "pdfUrl": "https://google.com",
            "discipline": "Planejamento"
          }
        ]
      }
    ]
  }
]

Seek the relationship between disciplines and teachers

GET /teachersdisciplines

Request:

Headers:

Send the token (Bearer token)
Params Type Description
Authorization string required, Starting with Bearer

Response:

Error cases:

Status code Cause
400 Request in wrong format
401 Invalid token
426 Outdated token
498 Expired token

Success case (status code 200:)

[
  {
    "disciplineId": 1,
    "discipline": "HTML e CSS",
    "teachers": [
      {
        "teacherDisciplineId": 1,
        "teacherId": 1,
        "teacher": "Diego Pinho"
      }
    ]
  },
  {
    "disciplineId": 2,
    "discipline": "JavaScript",
    "teachers": [
      {
        "teacherDisciplineId": 2,
        "teacherId": 1,
        "teacher": "Diego Pinho"
      }
    ]
  },
  {
    "disciplineId": 3,
    "discipline": "React",
    "teachers": [
      {
        "teacherDisciplineId": 3,
        "teacherId": 1,
        "teacher": "Diego Pinho"
      }
    ]
  },
  {
    "disciplineId": 4,
    "discipline": "Humildade",
    "teachers": [
      {
        "teacherDisciplineId": 4,
        "teacherId": 2,
        "teacher": "Bruna Hamori"
      }
    ]
  },
  {
    "disciplineId": 5,
    "discipline": "Planejamento",
    "teachers": [
      {
        "teacherDisciplineId": 5,
        "teacherId": 2,
        "teacher": "Bruna Hamori"
      }
    ]
  },
  {
    "disciplineId": 6,
    "discipline": "Autoconfiança",
    "teachers": [
      {
        "teacherDisciplineId": 6,
        "teacherId": 2,
        "teacher": "Bruna Hamori"
      }
    ]
  }
]

Search for registered disciplines

GET /categories

Request:

Headers:

Send the token (Bearer token)
Params Type Description
Authorization string required, Starting with Bearer

Response:

Error cases:

Status code Cause
400 Request in wrong format
401 Invalid token
426 Outdated token
498 Expired token

Success case (status code 200:)

[
  {
    "id": 1,
    "name": "Projeto",
    "createdAt": "2022-09-13T16:32:59.540Z"
  },
  {
    "id": 2,
    "name": "Prática",
    "createdAt": "2022-09-13T16:32:59.540Z"
  },
  {
    "id": 3,
    "name": "Recuperação",
    "createdAt": "2022-09-13T16:32:59.540Z"
  }
]

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

DATABASE_URL = postgres://UserName:Password@Hostname:5432/DatabaseName

PORT = number #recommended:5000

JWT_SECRET = any string

SUPABASE_URL = Project URL from supabase

SUPABASE_KEY = service_role from supabase

Supabase

guide to create a buckets in Supabase


Run Locally

Clone the project

  git clone https://github.com/ThVinicius/repoProvas_backEnd.git

Go to the project directory

  cd repoProvas_backEnd

Install dependencies

  npm install

Create database

  npx prisma migrate dev

Create seed

  npm run seed

Start the server

  npm run dev

Acknowledgements


Authors

  • Vinicius Pacheco is a student at Driven Education and is putting effort into it to switch careers. Nowadays he works with Engineering, looking forward to become a Dev.

About

https://repo-provas.fly.dev/


Languages

Language:TypeScript 99.1%Language:Shell 0.9%