Skip to content

franco-paganucci/tp-final-tp2

Repository files navigation

tp-final-tp2

Food Delivery E-Commerce Backend

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.


Features

  • 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.

Prerequisites

  • 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
    

Installation

  1. Clone the repository:

    git clone [email protected]:franco-paganucci/tp-final-tp2.git
    cd tp-final-tp2
  2. Install dependencies:

    npm install
  3. Set up the environment file: Create a .env file in the root directory and configure it as shown in the Prerequisites section.

  4. Start the application: For development, it is recommended to run the app in dev mode so it watches for changes.

    npm run dev

Endpoints

User Endpoints (/users)

POST /login

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"
}

GET /

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
  }
]

GET /

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
  }
]

POST /

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
  },
}

PUT /

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
  },
}

DELETE /

Description: Soft delete a user (Admins only).

Params

  • id: string

Headers

{
    "Authorization": "Bearer jwt_token"
}

Response:

{
  "message": "User soft deleted successfully"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published