Tradelous Backend
Backend service for the Tradelous Desktop and Tradelous Mobile applications, providing comprehensive API endpoints and data management for users, companies, products, and sales. Built as a robust foundation to support the frontend applications.

Contents
🛠️ Technologies
Built with:
🚀 Getting Started
Prerequisites
Before running the backend service, ensure the following tools are installed on your system:
Installation & Setup
# Clone the repository
$ git clone https://github.com/RiadOliveira/Tradelous-backend.git
# Navigate to project directory
$ cd Tradelous-backend
# Install dependencies
$ npm install
# Environment Configuration
# Copy example files and configure your environment
$ cp .env.example .env
$ cp ormconfig.example.json ormconfig.json
# Configure database connection in ormconfig.json
# Update the following fields with your PostgreSQL credentials:
# "username": "your_username",
# "password": "your_password",
# "database": "your_database_name"
# Run database migrations
$ npm run typeorm migration:run
# Start the development server
$ npm run dev
API Testing
For comprehensive API testing, an Insomnia collection is available with all configured endpoints: tradelous-insomnia.json.
⚙️ Features
- Authentication & Authorization - Complete user authentication system with JWT tokens, password recovery, and role-based access control for administrators and employees.
- User Management - Full user lifecycle management including registration, profile updates, avatar handling, and account deletion with proper data cleanup.
- Company Administration - Comprehensive company management with registration, employee hiring/firing, and administrative controls for business operations.
- Product Catalog System - Complete CRUD operations for product management with image handling, barcode support, and inventory tracking.
- Sales Transaction Management - Sales recording system with multiple payment methods, quantity tracking, and comprehensive reporting capabilities.
- File Upload Handling - File upload and management for user avatars, company logos, and product images.
- Data Analytics - Flexible sales reporting with date-range filtering (daily, weekly, monthly) and employee-specific sales tracking.
- Email Integration - Password recovery system with email notifications using Ethereal for development testing.
🗃️ Database Entities
User
- id: UUID
- name: string
- email: string
- password: string
- isAdmin: boolean - Administrator privileges (false if not associated with a company)
- companyId: UUID/null
- avatar: string/null - Avatar image filename
Company
- id: UUID
- name: string
- cnpj: number
- address: string
- logo: string/null - Company logo filename
- adminId: string
Product
- id: UUID
- name: string
- companyId: UUID
- price: number
- quantity: number
- brand: string
- barCode: string/null
- image: string/null - Product image filename
Sale
- id: UUID
- companyId: UUID
- employeeId: UUID
- productId: UUID
- date: Date - Sale timestamp (auto-generated)
- method: string - Payment method ('money' or 'card')
- totalPrice: number - Total sale amount (price × quantity)
🔗 API Endpoints
User Routes (/user)
POST /sign-up
Creates a new user account
- Request: name, email, password, confirmPassword
- Response: User object with generated ID and timestamps
POST /sessions
Generates authentication token for login
- Request: email, password
- Response: User object and JWT token
POST /forgot-password
Sends recovery email with reset token
- Request: email
- Response: No content (email sent via Ethereal)
POST /recover-password
Updates password using recovery token
- Request: confirmEmail, newPassword, confirmPassword, recoverToken
- Response: No content
PUT /
Updates authenticated user's profile
- Request: name, email, oldPassword (optional), newPassword (optional), confirmPassword (optional)
- Response: Updated user object
PATCH /update-avatar
Updates or removes user avatar
- Request: avatar file (multipart/form-data)
- Response: Updated user object
PATCH /leave-company
Removes user from associated company
- Request: No body required
- Response: No content
DELETE /
Deletes user account and associated data
- Request: No body required
- Response: No content
Company Routes (/company)
GET /
Retrieves authenticated user's company information
- Request: No body required
- Response: Company object
POST /
Creates new company with user as administrator
- Request: name, cnpj, address
- Response: Company object with generated ID
GET /list-employees
Lists all company employees and administrator
- Request: No body required
- Response: Array of user objects
[Admin Only] PUT /
Updates company information
- Request: name, cnpj, address
- Response: Updated company object
[Admin Only] PATCH /update-logo
Updates or removes company logo
- Request: logo file (multipart/form-data)
- Response: Updated company object
[Admin Only] PATCH /hire-employee/:employeeId
Associates user with company
- Request: Employee ID via URL parameter
- Response: Updated employee object
[Admin Only] PATCH /fire-employee/:employeeId
Removes employee from company
- Request: Employee ID via URL parameter
- Response: No content
[Admin Only] DELETE /
Deletes company and dissociates all employees
- Request: No body required
- Response: No content
Product Routes (/products)
GET /
Retrieves all company products
- Request: No body required
- Response: Array of product objects
POST /
Adds new product to company catalog
- Request: name, price, quantity, brand, barCode (optional), image (optional)
- Response: Product object with generated ID
PUT /:productId
Updates existing product information
- Request: name, price, quantity, brand, barCode (optional)
- Response: Updated product object
PATCH /update-image/:productId
Updates or removes product image
- Request: image file (multipart/form-data)
- Response: Updated product object
DELETE /:productId
Removes product from catalog
- Request: Product ID via URL parameter
- Response: No content
Sales Routes (/sales)
GET /employee/:employeeId
Retrieves all sales made by specific employee
- Request: Employee ID via URL parameter
- Response: Array of sale objects
GET /day/:day-:month-:year
Retrieves sales for specific date
- Request: Date via URL parameters (DD-MM-YYYY format)
- Response: Array of sale objects
GET /week/:day-:month-:year
Retrieves sales for 7-day period starting from specified date
- Request: Start date via URL parameters (DD-MM-YYYY format)
- Response: Array of sale objects
GET /month/:day-:month-:year
Retrieves sales for 30-day period starting from specified date
- Request: Start date via URL parameters (DD-MM-YYYY format)
- Response: Array of sale objects
POST /
Records new product sale
- Request: productId, method, quantity
- Response: Sale object with calculated total price
PUT /:saleId
Updates existing sale record
- Request: productId, method, quantity
- Response: Updated sale object
DELETE /:saleId
Removes sale record
- Request: Sale ID via URL parameter
- Response: No content
📝 License
This project is MIT Licensed. See
LICENSE file for more details.
👨💻 Author
Ríad Oliveira
🌐 Socials