Skip to content

Repository files navigation

Point of Sales System

Overview

This is a backend application for a Point of Sales system built with TypeScript, Node.js, and Fastify. It includes functionalities for user authentication, product management, upsell product management, and sales transactions. Sequelize is used as the ORM for MySQL database interactions.

Table of Contents

Getting Started

Prerequisites

  • Node.js (>= 14.x)
  • npm (>= 6.x)
  • MySQL

Installation

  1. Clone the repository:
            
              git clone repository_url
              cd repository_name
            
          
  2. Install dependencies:
            npm install
          
  3. Install MySQL:
            Windows: Download the MySQL Installer from the official MySQL website and follow the installation instructions.
          
  4. Set up the database:
            CREATE DATABASE pos_db;
          
  5. Create a .env file in the root directory and add your database configuration:
            
              DB_HOST=localhost
              DB_USER=root
              DB_PASSWORD=yourpassword
              DB_NAME=pos_db
              JWT_SECRET=your_jwt_secret
            
          

Environment Variables

Ensure the following environment variables are set in your .env file:

    
      DB_HOST=localhost
      DB_USER=root
      DB_PASSWORD=yourpassword
      DB_NAME=pos_db
      JWT_SECRET=your_jwt_secret
      PORT=3000
    
  

Running the Application

To start the server:

    npm start
  

The server will start on http://localhost:3000.

Running Tests

To run the unit tests:

    npm test
  

This will run all the test suites in the tests directory.

API Descriptions

User Authentication

  • Sign Up: This endpoint creates a new user account. It accepts an email and password, hashes the password for security, and generates a JWT token for authentication.
  • Login: This endpoint logs in an existing user. It verifies the user's credentials, checks the hashed password, and generates a JWT token for authentication.

Product Management

  • Create Product: This endpoint creates a new product. It accepts details like name, price, description, and quantity of the product and stores it in the database.
  • Retrieve All Products: This endpoint retrieves all products from the database. It returns a list of products with their details.
  • Update Product: This endpoint updates an existing product. It accepts the product ID and updated details, and then updates the product in the database.
  • Delete Product: This endpoint deletes an existing product. It accepts the product ID and removes the product from the database.

Transaction Management

  • Create Transaction: This endpoint creates a new transaction with details of products sold and their quantities. It checks the availability of the products, reduces their quantities accordingly, and adds the transaction details to the database. If the product quantity is insufficient, it returns an error.
  • Retrieve All Transactions: This endpoint retrieves all transactions. It returns a list of transactions with their details, including the associated products and upsell products.
  • Retrieve Specific Transaction: This endpoint retrieves a specific transaction by ID along with the associated products and upsell products. It provides detailed information about the transaction.

Upsell Product Management

  • Link Upsell Product: This endpoint links an upsell product to an existing product. It accepts the IDs of the main product and the upsell product, and creates a link between them in the database.
  • Retrieve Upsell Products: This endpoint retrieves all upsell products linked to a specific product. It returns a list of upsell products associated with the given product ID.

Future Enhancements

To ensure the system can be easily expanded in the future, several potential enhancements have been considered:

  • Discount Management: Implementing a system to manage discounts and promotions that can be applied to transactions.
  • Inventory Management: Adding features for managing inventory, including automated stock replenishment alerts and detailed inventory reports.
  • Customer Management: Introducing a customer relationship management (CRM) module to track customer details, purchase history, and preferences.
  • Reporting and Analytics: Developing advanced reporting and analytics tools to provide insights into sales performance, customer behavior, and product trends.
  • Multi-language Support: Expanding the system to support multiple languages for a more inclusive user experience.

The current architecture, using Fastify and Sequelize, is designed to be modular and scalable, making it easier to integrate these additional features in the future.

About

This is a backend application for a Point of Sales system built with TypeScript, Node.js, and Fastify. It includes functionalities for user authentication, product management, upsell product management, and sales transactions. Sequelize is used as the ORM for MySQL database interactions.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages