Welcome to the Store-api! This project is a comprehensive Node.js application built to manage various aspects of a hypothetical system, offering functionalities for user management, product handling, order processing, and financial transactions. The API leverages the Express.js framework for robust route handling and Prisma ORM for seamless interaction with the database.
-
Node.js: A JavaScript runtime for server-side development.
-
Express.js: A web application framework for Node.js, simplifying route handling and middleware integration.
-
Prisma ORM: An open-source database toolkit for TypeScript and Node.js that simplifies database interactions.
-
Swagger: API documentation tool for clear and accessible API exploration.
-
Multer: A middleware for handling multipart/form-data, useful for file uploads.
-
Cron: A time-based job scheduler for running periodic tasks.
-
User Management: Create and authenticate users, manage user roles, and retrieve user information.
-
Product Operations: Handle products, categories, and their associations, enabling efficient product management.
-
Client and Wallet Management: Create and manage clients, their wallets, and credit transactions.
-
Order Processing: Facilitate the creation, retrieval, and modification of orders, associating them with clients and products.
-
Financial Transactions: Track and manage financial transactions, providing insights into credit changes and financial activities.
# Clone the repository
git clone https://github.com/Enrickyb/store-api.git
# Navigate to the project directory
cd store-api
# Install dependencies
npm install
- /src
- /controllers
- /middlewares
- /providers
- /routes
- /uploads
- /docs
- /tests
POST /api/users/create
Creates a new user.
- Headers:
Content-Type: application/json
{
"username": "example",
"password": "examplepassword"
}
- Status: 201 Created
- Body:
{
"message": "User created successfully"
}
POST /api/users/login
Logs in a user.
- Headers:
Content-Type: application/json
{
"username": "example",
"password": "examplepassword"
}
- Status: 200 OK
- Body:
{
"token": "your-auth-token"
}
GET /api/users/client/:client_id
Gets all users of a specific client.
- Headers:
Authorization: Bearer your-auth-token
- Status: 200 OK
- Body:
[
{
"id": 1,
"username": "user1"
},
{
"id": 2,
"username": "user2"
}
// ...
]
POST /api/products/create
Creates a new product.
- Headers:
Authorization: Bearer your-auth-token
Content-Type: multipart/form-data
- Form Data:
file
: Product filethumbnail
: Product thumbnailname
: Product nameprice
: Product pricecategory_id
: Category ID
- Status: 201 Created
- Body:
{
"message": "Product created successfully"
}
GET /api/products/all
Gets all products.
- Headers:
Authorization: Bearer your-auth-token
- Status: 200 OK
- Body:
[
{
"id": 1,
"name": "Product1",
"price": 20.00,
"categoryId": 1
},
{
"id": 2,
"name": "Product2",
"price": 30.00,
"categoryId": 2
}
// ...
]
Provide information about the purpose and functionality of each controller in your project.
UserController
: Manages user-related logic.ProductController
: Handles product-related operations.
Explain the purpose of each middleware and when it is used.
authMiddleware
: Validates user authentication.serverAdminMiddleware
: Ensures the user has server admin privileges.
List and describe the models used in your project. Include details about each model's fields and relationships.
User
: Represents a user with fields likeusername
andpassword
.Product
: Represents a product with fields likename
andprice
.
Em desenvolvimento
# Run tests
npm test