The FMGC (Fast-Moving Consumer Goods) Commercial App is a RESTful API designed for managing products and customers. It provides endpoints for user registration, authentication, managing products, and fetching customer data.
- Express.js
- Mongoose
- Joi
- Dotenv
- Bcrypt
- JSON Web Token (JWT)
- Endpoint:
/user/register
- Method: POST
- Description: Registers a new user.
- Request Body:
username
: Username of the user.password
: Password of the user.role
: Role of the user (admin or user).
- Endpoint:
/user/login
- Method: POST
- Description: Logs in a user and generates a JWT token.
- Request Body:
username
: Username of the user.password
: Password of the user.
- Endpoint:
/user/allcustomers
- Method: GET
- Description: Retrieves customers data with pagination.
- Authorization: Required (admin token)
- Query Parameters:
page
: Page number for pagination.
- Response: Returns a list of customers with default limit of 5 items per page.
- Endpoint:
/products/allproducts
- Method: GET
- Description: Retrieves all products data with pagination.
- Query Parameters:
page
: Page number for pagination.
- Authorization: Not required
- Response: Returns a list of products with default limit of 5 items per page.
- Endpoint:
/products/addProduct
- Method: POST
- Description: Adds a new product to the database.
- Authorization: Required (admin token)
- Request Body:
name
: Name of the product.category
: Category of the product.price
: Price of the product.
- Endpoint:
/products/updateProduct
- Method: PUT
- Description: Updates an existing product in the database.
- Authorization: Required (admin token)
- Request Body:
_id
: ID of the product to update.updated
: Object containing updated fields (name, category, price).
- Endpoint:
/products/deleteProduct/:id
- Method: DELETE
- Description: Deletes a product from the database.
- Authorization: Required (admin token)
- Parameters:
id
: ID of the product to delete.
- Endpoint:
/products/filter
- Method: GET
- Description: Filters products based on category, price, name, and pagination.
- Authorization: Not required
- Query Parameters:
category
: Category name to filter products.minprice
: Minimum price to filter products.maxprice
: Maximum price to filter products.name
: Product name to filter products.page
: Page number for pagination.
- Response: Returns a list of filtered products with default limit of 5 items per page.
- Users can register and log in using username and password.
- Upon login, a JWT token is generated that expires in 2 hours.
- Admins have access to all endpoints.
- Users have restricted access to certain endpoints.
- Pagination is implemented for endpoints
/user/allcustomers
,/products/allproducts
, and/products/filter
. - Default limit is set to 5 items per page.
- Clone the repository: FMGC Commercial App
- Install Node Modules
- Run the Server