Task Description:
Create a small application that allows authenticated users to manage a product inventory, log sales transactions, and generate basic sales reports. This involves developing a RESTful API, a database schema, and a user interface.
Frontend Requirements:
- Set up a React project using TypeScript.
- Implement user authentication:
- Implement a login page allowing users to authenticate using a username and password.
- Use tokens (e.g., JWT) to manage user sessions and secure endpoints.
- Develop a user interface with the following authenticated functionalities:
- Display a list of products.
- Add a new product with the following fields:
- Product ID: Unique identifier for each product.
- Name: Descriptive name of the product.
- Description: Brief details about the product.
- Price: Current price of the product (must be a positive number).
- Quantity in Stock: Number of units available in inventory.
- Update product details or quantities.
- Delete a product from the inventory list.
- A search bar to filter products based on product name.
- Sort options to sort the product list by Name and Price (ascending and descending).
- Enable logging of sales transactions for products, including:
- Product ID
- Quantity Sold
- Date of Sale
- Provide a report view showing:
- Total sales for each product.
- Total revenue for each product.
- Implement error handling and validation for all input fields and authentication processes.
Backend Requirements:
- Set up a Node.js project with Express.js and TypeScript.
- Implement authentication using JWT to secure the endpoints:
- POST /auth/login: Authenticate users and return an access token.
- Middleware to protect routes and verify user tokens.
- Implement the following RESTful API endpoints for authenticated users:
- GET /products: Retrieve a list of all products, optionally filtered by a search query and sorted by specified criteria.
- POST /products: Add a new product to the inventory.
- PUT /products/:id: Update existing product details or quantity if necessary.
- DELETE /products/:id: Remove a product from the inventory by ID.
- POST /sales: Log a sales transaction, updating product sales data and adjusting inventory quantities.
- GET /reports/sales: Generate a report summary for all products.
- Use MySQL with TypeORM to create database schemas for storing user information, product details, and sales transactions.
- Implement validations and handle data integrity for both authentication and CRUD operations.
Database Requirements:
- Set up a MySQL database and configure a connection using TypeORM.
- Create tables for
Users
,Products
, andSales
with appropriate columns and data types:Users
table should store user credentials securely.Products
table should store product information, including stock quantity.Sales
table should track sales transactions associated with products.
Additional Functionality:
-
Authentication:
- Secure authentication process, including password hashing.
- Use JWT for managing user sessions and securing API routes.
-
Sales Logging:
- Implement the ability to log a sale for a specific product, updating inventory and sales records accurately.
-
Sales Reports:
- Generate a report that provides total quantity sold and total revenue per product.
- Implement API logic to aggregate sales data properly.
-
Search and Sort:
- Add search functionality to filter the list of products by name.
- Add sort functionality to allow sorting of the product list by name and price.
Acceptance Criteria:
- The React application securely handles user authentication and manages sessions.
- Inventory management is available only to authenticated users, involving adding, updating, and deleting products, with stock levels accurately reflecting sales transactions.
- Reports are generated accurately, reflecting total sales and revenue for each product.
- Proper database setup includes
Users
,Products
, andSales
tables with accurate, retrievable, and consistent data. - Code should be well-organized, readable, and conform to best practices in TypeScript and security standards.
Expectations:
- This task assesses the developer's proficiency in the tech stack and their ability to handle secure data handling, authentication, and authorization.
- If there are any gaps or assumptions needed within the task, developers are encouraged to make reasonable assumptions and document these assumptions clearly in their code or accompanying documentation.
- The developer should be able to explain their design and implementation decisions if asked.
Developers are encouraged to reach out for any clarifications during the task.