Project Name: tp-taller-de-programacion-2
Version: 1.0.0
Description: This Express.js application serves as the backend for a food delivery e-commerce platform. It handles user authentication, user management, product management, order processing, and role-based access control. The app uses Sequelize for database interactions and JWT for secure authentication.
- User Authentication: Secure login with JWT.
- User Management: CRUD operations for user data.
- Role-based Access Control: Restrict endpoints based on user roles (admin, employee, customer).
- Soft Delete: Implements paranoid mode for user data.
- Password Security: Passwords are hashed using bcrypt.
- Node.js: v16.x or later
- MySQL: 8.x or compatible (or any other supported database by modifying the connection configuration in Sequelize, i.e. SQL Server).
- Environment Variables: Configure a
.env
file with the following variables:DB_NAME=your_database_name DB_USER=your_database_user DB_PASSWORD=your_database_password DB_HOST=localhost DB_PORT=3306 DB_DIALECT=mysql JWT_SECRET=your_jwt_secret
-
Clone the repository:
git clone [email protected]:franco-paganucci/tp-final-tp2.git cd tp-final-tp2
-
Install dependencies:
npm install
-
Set up the environment file: Create a
.env
file in the root directory and configure it as shown in the Prerequisites section. -
Start the application: For development, it is recommended to run the app in dev mode so it watches for changes.
npm run dev
Description: Authenticate user and generate JWT.
Request Body:
{
"mail": "[email protected]",
"password": "securepassword"
}
Response:
{
"user": {
"id": 1,
"mail": "[email protected]",
"roleId": 2
},
"token": "jwt_token"
}
Description: Get a list of all users (Admins/Employees only).
Headers
{
"Authorization": "Bearer jwt_token"
}
Response:
[
{
"id": 1,
"name": "John Doe",
"mail": "[email protected]",
"address": "123 Main St",
"roleId": 1
}
]
Description: Get user details by ID (Admins/Employees only).
Params
- id: string
Headers
{
"Authorization": "Bearer jwt_token"
}
Response:
[
{
"id": 1,
"name": "John Doe",
"mail": "[email protected]",
"address": "123 Main St",
"roleId": 1
}
]
Description: Create (register) a new user.
Request Body:
{
"name": "Jane Doe",
"mail": "[email protected]",
"address": "456 Side St",
"password": "newsecurepassword",
"roleId": 2
}
Response:
{
"user": {
"id": 1,
"mail": "[email protected]",
"roleId": 2
},
}
Description: Update user details.
Params
- id: string
Headers
{
"Authorization": "Bearer jwt_token"
}
Request Body:
{
"name": "Jane Doe",
"roleId": 3
}
Response:
{
"user": {
"name": "Jane Doe",
"id": 1,
"mail": "[email protected]",
"roleId": 3
},
}
Description: Soft delete a user (Admins only).
Params
- id: string
Headers
{
"Authorization": "Bearer jwt_token"
}
Response:
{
"message": "User soft deleted successfully"
}