Skip to content

Instantly share code, notes, and snippets.

@shri-kanth
Last active January 24, 2025 10:10
Show Gist options
  • Save shri-kanth/6a2ec1d9ce8892eb132630c01aaec828 to your computer and use it in GitHub Desktop.
Save shri-kanth/6a2ec1d9ce8892eb132630c01aaec828 to your computer and use it in GitHub Desktop.
Task 1

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:

  1. Set up a React project using TypeScript.
  2. 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.
  3. 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).
  4. Enable logging of sales transactions for products, including:
    • Product ID
    • Quantity Sold
    • Date of Sale
  5. Provide a report view showing:
    • Total sales for each product.
    • Total revenue for each product.
  6. Implement error handling and validation for all input fields and authentication processes.

Backend Requirements:

  1. Set up a Node.js project with Express.js and TypeScript.
  2. 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.
  3. 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.
  4. Use MySQL with TypeORM to create database schemas for storing user information, product details, and sales transactions.
  5. Implement validations and handle data integrity for both authentication and CRUD operations.

Database Requirements:

  1. Set up a MySQL database and configure a connection using TypeORM.
  2. Create tables for Users, Products, and Sales 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:

  1. Authentication:

    • Secure authentication process, including password hashing.
    • Use JWT for managing user sessions and securing API routes.
  2. Sales Logging:

    • Implement the ability to log a sale for a specific product, updating inventory and sales records accurately.
  3. Sales Reports:

    • Generate a report that provides total quantity sold and total revenue per product.
    • Implement API logic to aggregate sales data properly.
  4. 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:

  1. The React application securely handles user authentication and manages sessions.
  2. Inventory management is available only to authenticated users, involving adding, updating, and deleting products, with stock levels accurately reflecting sales transactions.
  3. Reports are generated accurately, reflecting total sales and revenue for each product.
  4. Proper database setup includes Users, Products, and Sales tables with accurate, retrievable, and consistent data.
  5. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment