Skip to content

ricardobarbosadev/POS-System

Repository files navigation

API POS-Cubos

API developed as the final challenge of the Cubos Academy back-end software development course. It is a POS (Point of Sale) system.

📜 Summary

  1. Project details
  2. Deploy
  3. To run the project in a development environment
  4. Documentation
  5. Technologies used
  6. Authors

1. 🔍 Project details

The POS_Cubos API aims to control the sales of a fictitious store. It was carried out academically during the back-end software development course at Cubos Academy.

Scenario:

  • The system allows user registration, with information validation;
  • The system only allows user registration, login and category listing requests without authentication through JWT;
  • With the user logged in, the system allows editing and detailing of user information, creation, editing, detailing and listing of customers, creation, editing, detailing, deletion and listing of products, creation and listing of orders;
  • The system allows the inclusion of product images, which are stored in a cloud storage service;
  • The system automatically decreases the quantity of items in stock according to the order placed;
  • The system sends an email to the customer upon successful order placement;

2. ✅ Deploy

The API is running on the Cyclic server: Deploy link.

To use it, simply follow the documentation present in this content.

3. 🔌 To run the project in a development environment

  1. Install the necessary dependencies to run the API (listed in package.json):

    npm install
    
  2. The API uses PostgreSQL as a database running on an ElephantSQL server. The API also makes use of a bucket on BackBlaze for storing images, as well as a service on [Brevo](https://www.brevo.com/pt /) for SMTP server.

  3. Therefore, it is necessary to create the respective services for the API to consume and fill in the .env file using the .env.example example for the names of the environment variables.

  4. Run the application and the system will automatically create the tables in the database, leaving them ready for use.

  5. You will need a request testing tool like Insomnia, and you must follow the guidance in the documentation below to use the API.

  6. You can run automated tests created with Jest:

    npm run test
    

4. 📖 Documentation

Endpoints

Login - User authentication

POST login

Log in with a user using email and password. Returns a JWT token to be used in requests.

Request

Name Mandatory Type Description
email yes string User email
senha yes string User password

NOTE: No need to send JWT Token via Authorization Header

Requisition Example:

{
  "email": "fulano@email.com",
  "senha": "password"
}

Response

Success

{
  "type": "Bearer",
  "token": "abcdefghijklmno.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnop"
}

status: 200

Common errors

{
  "message": "Invalid email and/or password."
}

status: 401


User - Creating a new user, editing a user, and drilling down on the user

POST usuario

Create a user to be able to use the API.

Request

Name Mandatory Type Description
nome yes string User name
email yes string User email
senha yes string User password

NOTE:_ No need to send JWT Token via Authorization Header.

Request example:

{
  "nome": "Fulano",
  "email": "fulano@email.com",
  "senha": "password"
}

Response

Success

{
  "id": 1,
  "nome": "Fulano",
  "email": "fulano@email.com"
}

status: 201

Common errors

{
  "message": "Email already exists."
}

status: 400

{
  "message": "The password must be at least 6 characters"
}

status: 400

PUT usuario

Edit a user. Only name and email can be edited (or just one of the two).

Request

Name Mandatory Type Description
nome yes string User name
email yes string User email
password yes string User password

NOTA: It is necessary to send JWT Token via Authorization Header.

Request example:

{
  "nome": "Fulano Editado",
  "email": "fulano.editado@email.com",
  "senha": "password"
}

Response

Success
no body returned for response
status: 204

Common errors

{
  "message": "Email already in use"
}

status: 400

GET usuario

Detail a user. The id is automatically sent with the token..

Request

It is not necessary to send data in the request

Note:_ It is necessary to send JWT Token via Authorization Header.

Response

Success

{
  "id": 1,
  "nome": "Fulano",
  "email": "fulano@email.com"
}

status: 200
Common Errors

{
  "message": "User not found."
}

status: 404


Category - List of product categories

GET categoria

List categories.

Request

It is not necessary to send data in the request

NOTE:_ It is not necessary to send JWT Token via Authorization Header.

Response

Success

[
  {
    "id": 1,
    "descricao": "Informática"
  },
  {
    "id": 2,
    "descricao": "Celulares"
  },
  {
    "id": 3,
    "descricao": "Beleza e Perfumaria"
  }
]

status: 200

Success without return

[]

status: 200


Customer - Creating a new customer, editing a customer, listing customers and detailing a customer

POST cliente

Creating a customer.

Request

Name Mandatory Type Description
nome yes string User name
email yes string User Email
cpf yes string User CPF
cep no string User's adress cep
rua no string User's adress street
numero no string User's adress number
bairro no string User's adress neighborhood
cidade no string User's adress city
estado no string User's adress state

NOTE:_ It is necessary to send JWT Token via Authorization Header.

Request example:

{
  "nome": "Ciclano",
  "email": "ciclano@gmail.com",
  "cpf": "12345678911",
  "cep": "12345678",
  "rua": "Rua 1",
  "numero": "11-A",
  "bairro": "Bairro 1",
  "cidade": "Cidade 1",
  "estado": "Estado 1"
}

Response

Sucesso

{
  "id": 3,
  "nome": "Ciclano",
  "email": "ciclano@gmail.com",
  "cpf": "12345678911",
  "cep": "12345678",
  "rua": "Rua 1",
  "numero": "11-A",
  "bairro": "Bairro 1",
  "cidade": "Cidade 1",
  "estado": "Estado 1"
}

status: 201

Common Errors

{
  "message": "Client already exists."
}

status: 400

GET cliente

Listar clientes.

Request

It is not necessary to send data in the request

NOTA: It is necessary to send JWT Token via Authorization Header.

Response

Success

[
  {
    "id": 1,
    "nome": "Beltrano",
    "email": "beltrano@email.com",
    "cpf": "12345678910",
    "cep": null,
    "rua": null,
    "numero": null,
    "bairro": null,
    "cidade": null,
    "estado": null
  },
  {
    "id": 2,
    "nome": "Ciclano",
    "email": "ciclano@gmail.com",
    "cpf": "12345678911",
    "cep": "12345678",
    "rua": "Rua 1",
    "numero": "11-A",
    "bairro": "Bairro 1",
    "cidade": "Cidade 1",
    "estado": "Estado 1"
  }
]

status: 200

Success without return

[]

status: 200

GET cliente-id

Detail a customer. The id must be sent in the url.

Request

Name Mandatory Type Description
id yes number Send via route parameter

NOTE: It is necessary to send JWT Token via Authorization Header.

Response

Success

{
  "id": 2,
  "nome": "Ciclano",
  "email": "ciclano@gmail.com",
  "cpf": "12345678911",
  "cep": "12345678",
  "rua": "Rua 1",
  "numero": "11-A",
  "bairro": "Bairro 1",
  "cidade": "Cidade 1",
  "estado": "Estado 1"
}

status: 200

Common Errors

{
  "message": "Client not found."
}

status: 404

PUT cliente-id

Change customer data. The id must be sent in the url.

Request

Name Mandatory Type Description
id yes number Send via route parameter
nome yes string User name
email yes string Email do User
cpf yes string User CPF
cep no string User's adress cep
rua no string User's adress street
numero no string User's adress number
bairro no string User's adress neighborhood
cidade no string User's adress city
estado no string User's adress state

NOTA: It is necessary to send JWT Token via Authorization Header.

Request example:

{
  "nome": "Ciclano Editado",
  "email": "ciclano.editado@gmail.com",
  "cpf": "12345678911",
  "cep": "12345678",
  "rua": "Rua 1",
  "numero": "11-A",
  "bairro": "Bairro 1",
  "cidade": "Cidade 1",
  "estado": "Estado 1"
}

Response

Sucesso
no body returned for response
status: 204

Common Errors

{
  "message": "Client not found."
}

status: 404

{
  "message": "Email already exists."
}

status: 400

{
  "message": "CPF already exists."
}

status: 400


Product - Creating a new product, editing a product, listing products, deleting a product and detailing a product

POST produto

Criar um produto.

Request

Name Mandatory Type Description
descricao yes string Product Description
quantidade_estoque yes number Quantity of items in stock
valor yes number Product value (in cents)
categoria_id yes number Product category id
produto_imagem no file Product image file

NOTE: It is necessary to send JWT Token via Authorization Header.

Response

Success

{
  "id": 1,
  "descricao": "Teclado",
  "quantidade_estoque": 50,
  "valor": 10000,
  "categoria_id": 1,
  "produto_imagem": "url_da_imagem"
}

status: 201

Common Errors

{
  "message": "Category not found."
}

status: 404

{
  "message": "Description already exists."
}

status: 400

GET produto

List products. A query parameter categoria_id can be passed to list only products from a specific category..

Request

Name Mandatory Type Description
categoria_id no number Send via query parameter in the route

NOTE: It is necessary to send JWT Token via Authorization Header.

Request example:

url/produto?categoria_id=1

Response

Success

[
  {
    "id": 1,
    "descricao": "Teclado X",
    "quantidade_estoque": 25,
    "valor": 10000,
    "categoria_id": 1,
    "produto_imagem": "url/Teclado_X/teclado_x.png"
  },
  {
    "id": 2,
    "descricao": "Teclado Y",
    "quantidade_estoque": 48,
    "valor": 20000,
    "categoria_id": 1,
    "produto_imagem": "url/Teclado_Y/teclado_y.png"
  }
]

status: 200

Success without return

[]

status: 200

GET produto-id

Detail a product. The id must be sent in the url.

Request

Nome Mandatory Type Description
id yes number Send via route parameter

NOTE: It is necessary to send JWT Token via Authorization Header.

Response

Success

{
  "id": 1,
  "descricao": "Teclado X",
  "quantidade_estoque": 25,
  "valor": 10000,
  "categoria_id": 1
}

status: 200

Common Errors

{
  "message": "Product not found."
}

status: 404

PUT produto-id

Change product data. The id must be sent in the url.

Request

Name Mandatory Type Description
id yes number Send via route parameter
descricao yes string Product Description
quantidade_estoque yes number Quantity of items in stock
valor yes number Product value (in cents)
categoria_id yes number Product category id
produto_imagem no file Product image file

NOTE: It is necessary to send JWT Token via Authorization Header.

Response

Sucesso
no body returned for response
status: 204

Common Errors

{
  "message": "Product not found."
}

status: 404

{
  "message": "Category not found."
}

status: 404

{
  "message": "Description already exists."
}

status: 400

DELETE produto-id

Delete a product. The id must be sent in the url.

Request

Name Mandatory Type Description
id yes number Send via route parameter

NOTE: It is necessary to send JWT Token via Authorization Header.

Response

Success no body returned for response
status: 204

Common Errors

{
  "message": "Product not found."
}

status: 404

{
  "message": "This product is linked to an order."
}

status: 400


Order - Creating a new order and order listing

POST pedido

Create a order.

Request

Name Mandatory Type Description
cliente_id yes number Customer ID
observacao no string Note for order
pedido_produtos yes array Array with products related to the order
produto_id yes number Product ID
quantidade_produto yes number Quantity of product items

NOTA: It is necessary to send JWT Token via Authorization Header.

Request example:

{
  "cliente_id": 1,
  "observacao": "Em caso de ausência recomendo deixar com algum vizinho",
  "pedido_produtos": [
    {
      "produto_id": 1,
      "quantidade_produto": 10
    },
    {
      "produto_id": 2,
      "quantidade_produto": 20
    }
  ]
}

Response

Success

{
  "pedido": {
    "id": 1,
    "cliente_id": 1,
    "observacao": "Em caso de ausência recomendo deixar com algum vizinho",
    "valor_total": 100000
  },
  "pedido_produtos": [
    {
      "id": 1,
      "pedido_id": 1,
      "produto_id": 1,
      "quantidade_produto": 10,
      "valor_produto": 5000
    },
    {
      "id": 2,
      "pedido_id": 1,
      "produto_id": 2,
      "quantidade_produto": 20,
      "valor_produto": 2500
    }
  ]
}

status: 201

Common Errors

{
  "message": "Client not found."
}

status: 404

{
  "message": "Product not found."
}

status: 404

{
  "message": "Insufficient stock."
}

status: 400

GET pedido

List orders. A query parameter cliente_id can be passed to list only orders from a specific client.

Request

Name Mandatory Type Description
cliente_id no number Send via query parameter in the route

NOTA: It is necessary to send JWT Token via Authorization Header.

Request example:

url/pedido?cliente_id=1

Response

Success

[
  {
    "pedido": {
      "id": 1,
      "cliente_id": 1,
      "observacao": "Em caso de ausência recomendo deixar com algum vizinho",
      "valor_total": 100000
    },
    "pedido_produtos": [
      {
        "id": 1,
        "pedido_id": 1,
        "produto_id": 1,
        "quantidade_produto": 10,
        "valor_produto": 5000
      },
      {
        "id": 2,
        "pedido_id": 1,
        "produto_id": 2,
        "quantidade_produto": 20,
        "valor_produto": 2500
      }
    ]
  },
  {
    "pedido": {
      "id": 2,
      "cliente_id": 1,
      "observacao": "Em caso de ausência recomendo deixar com algum vizinho",
      "valor_total": 10000
    },
    "pedido_produtos": [
      {
        "id": 3,
        "pedido_id": 2,
        "produto_id": 1,
        "quantidade_produto": 1,
        "valor_produto": 5000
      },
      {
        "id": 4,
        "pedido_id": 2,
        "produto_id": 2,
        "quantidade_produto": 2,
        "valor_produto": 2500
      }
    ]
  }
]

status: 200

Success without return

[]

status: 200

5. 💻 Technologies used

Languages, Frameworks & Librarys: JavaScript Node Express JSON JWT NPM ESLint Prettier Nodemon Git

Organization: Trello GitHub

Tests: Insomnia Jest

Database: PostgreSQL

IDE: VSCode

6. 👨‍💻 Authors

Created by Daniel M. Justo, Matheus O. da Silva, Ney H. M. Ribeiro, Raimundo F. da Silva Neto, Ricardo J. S. Barbosa.

Thanks for the visit!!

About

API developed as the final challenge of the Cubos Academy back-end software development course. It is a POS (Point of Sale) system.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors