NivaldoFarias / drivenpass-api

19ᵗʰ Project developed during Driven's Full Stack Develpment Bootcamp

Home Page:https://drivenpass-api-project.herokuapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Summary

Back end Development Project (19ᵗʰ)

Built with

heroku postgresql typescript node.js express.js json-web-tokens

Table of Contents

Getting Started

This Api can be used in two different ways: by cloning the project or by using your preferred client, such as Insomnia or Postman.

To clone the project, run the following command:

git clone https://github.com/NivaldoFarias/drivenpass-api.git

Then, navigate to the project folder and run the following command:

npm install

Finally, start the server:

npm start

You can now access the API's endpoints by navigating to http://localhost:5000/ or to the deployed URL https:/drivenpass-api-project.herokuapp.com/. If needed, import one of the provided Request Collections files into your preferred client and test the endpoints!

ps.: Highly recommend using the request collections to test the API.

API Reference

In this section, you will find the API's endpoints and their respective descriptions, along with the request and response examples, as well as the Prisma models for each entity, that can be used as guide for data formatting. All data is sent and received as JSON.

Models

User model users

  • id: A unique identifier for each user. serial4
  • username: The user's username. text
  • email: The user's email. An email may only be registered once. text
  • password: The user's password. text
  • created_at: The date and time when the user was created. timestamp

Note model notes

  • id: A unique identifier for each note. serial4
  • label: A label for the note. Each user can only have one note with the same label. Up to 50 characters long. text
  • content: The content of the note. Up to 1000 characters long. text
  • user_id: The user that created the note. int4
  • created_at: The date and time when the note was created. timestamp

Network model networks

  • id: A unique identifier for each network. serial4
  • label: A label for the network. Up to 50 characters long. text
  • password: The network password. The inserted data is encrypted, and decrypted upon query. text
  • user_id: The user that created the network. int4
  • created_at: The date and time when the network was created. timestamp

Document model documents

  • id: A unique identifier for each document. serial4
  • label: A label for the document. Each user can only have one document with the same label. Up to 50 characters long. text
  • full_name: The full name found on the document. text
  • emission_date: The emission date of the document. The date must follow the format DD/MM/YYYY.varhchar(10)
  • exp_date: The expiration date of the document. The date must follow the format DD/MM/YYYY.varhchar(10)
  • registry_number : The registry number of the document. text
  • issuing_agency: The issuing agency of the document. text
  • type: The document'd type. Must either be 'CNH' or 'RG'. enum
  • user_id: The user that created the document. int4
  • created_at: The date and time when the document was created. timestamp

Credential model credentials

  • id: A unique identifier for each credential. serial4
  • label: A label for the credential. Each user can only have one credential with the same label. Up to 50 characters long. text
  • username: The username of the credential. text
  • password: The password of the credential. The inserted data is encrypted, and decrypted upon query. text``text
  • url: The URL of the credential. text
  • user_id: The user that created the credential. int4
  • created_at: The date and time when the credential was created. timestamp

Credit card model credit_cards

  • id: A unique identifier for each credit card. serial4
  • label: A label for the credit card. Each user can only have one credit card with the same label. Up to 50 characters long. text
  • number: The credit card number. varhchar(16)
  • exp_date: The credit card expiration date. The date must follow the format MM/YY.varhchar(5)
  • cvc: The credit card CVC. The inserted data is encrypted, and decrypted upon query. text
  • password: The credit card password. The inserted data is encrypted, and decrypted upon query. text
  • owner: The credit card owner. text
  • is_virtual: Whether the credit card is virtual or not. bool
  • type: The credit card type. Must either be 'CREDIT', 'DEBIT' or 'BOTH'. enum
  • user_id: The user that created the credit card. int4
  • created_at: The date and time when the credit card was created. timestamp

Routes

Notes /notes

Networks /networks

Documents /documents

Credentials /credentials

Credit cards /credit-cards

Authentication

Register

POST /auth/register
Request
Body
{
  "username": "johndoe",
  "email": "john_doe@gmail.com",
  "password": "123456789"
}
Headers
{
  "Content-Type": "application/json"
}
Responses
Status Code Description Properties
201 Created data: {}
409 Email already registered error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Sign in

POST /auth/sign-in
Request
Body
{
  "email": "john_doe@gmail.com",
  "password": "123456789"
}
Headers
{
  "Content-Type": "application/json"
}
Responses
Status Code Description Properties
200 OK data: { token }
403 Invalid password error: { message, details }
404 User not found error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Notes

Create a note

POST /notes/create
Request
Body
{
  "label": "First note",
  "content": "This is a test! Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt."
}
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
201 Created data: {}
400 Missing headers error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
409 Conflict error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Search all notes

GET /notes/all
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { notes[] }
401 Missing token error: { message, details }
403 Invalid token error: { message, details }
500 Internal Server Error error: { message, details }

Search a note

GET /notes/:id
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { notes }
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Delete a note

DELETE /notes/:id/delete
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: {}
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Networks

Create a network

POST /networks/create
Request
Body
{
  "label": "House network",
  "password": "123456"
}
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
201 Created data: {}
400 Missing headers error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
409 Conflict error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Search all networks

GET /networks/all
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { networks[] }
401 Missing token error: { message, details }
403 Invalid token error: { message, details }
500 Internal Server Error error: { message, details }

Search a network

GET /networks/:id
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { networks }
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Delete a network

DELETE /networks/:id/delete
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: {}
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Documents

Create a document

POST /documents/create
Request
Body
{
  "label": "First Document",
  "full_name": "John Doe",
  "emission_date": "03/06/2020",
  "exp_date": "12/05/2025",
  "registry_number": "132456",
  "issuing_agency": "sass",
  "type": "RG"
}
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
201 Created data: {}
400 Missing headers error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
409 Conflict error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Search all documents

GET /documents/all
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { documents[] }
401 Missing token error: { message, details }
403 Invalid token error: { message, details }
500 Internal Server Error error: { message, details }

Search a document

GET /documents/:id
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { documents }
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Delete a document

DELETE /documents/:id/delete
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: {}
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Credentials

Create a credential

POST /credentials/create
Request
Body
{
  "label": "First credential",
  "username": "JohnDoe",
  "url": "https://facebook.com",
  "password": "123456789"
}
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
201 Created data: {}
400 Missing headers error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
409 Conflict error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Search all credentials

GET /credentials/all
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { credentials[] }
401 Missing token error: { message, details }
403 Invalid token error: { message, details }
500 Internal Server Error error: { message, details }

Search a credential

GET /credentials/:id
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { credentials }
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Delete a credential

DELETE /credentials/:id/delete
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: {}
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Credit cards

Create a credit card

POST /credit-cards/create
Request
Body
{
  "label": "First credit card",
  "number": "1234123412341324",
  "exp_date": "08/25",
  "password": "1234",
  "cvc": "123",
  "owner": "JOHN DOE",
  "is_virtual": false,
  "type": "BOTH"
}
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
201 Created data: {}
400 Missing headers error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
409 Conflict error: { message, details }
422 Invalid Input error: { message, details }
500 Internal Server Error error: { message, details }

Search all credit cards

GET /credit-cards/all
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { credit_cards[] }
401 Missing token error: { message, details }
403 Invalid token error: { message, details }
500 Internal Server Error error: { message, details }

Search a credit card

GET /credit-cards/:id
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: { credit_cards }
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Delete a credit card

DELETE /credit-cards/:id/delete
Request
Headers
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
}
Responses
Status Code Description Properties
200 OK data: {}
400 Invalid parameters error: { message, details }
401 Missing token error: { message, details }
403 Forbidden error: { message, details }
404 Not Found error: { message, details }
409 Conflict error: { message, details }
500 Internal Server Error error: { message, details }

Contact & Study Playlist

In the following Youtube link I included all Youtube content I used or refered to while studying for this project. Hope you enjoy it!

LinkedIn Slack Youtube

About

19ᵗʰ Project developed during Driven's Full Stack Develpment Bootcamp

https://drivenpass-api-project.herokuapp.com

License:MIT License


Languages

Language:TypeScript 99.9%Language:Procfile 0.1%