Skip to content

kunjrathi2004/Textile-CRM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

<<<<<<< HEAD Here is a detailed summary of what we have done so far to build a CRM application:

1. Setting Up the Backend Environment

  • Initialized Project: You started by setting up a Node.js project for your CRM system, with the necessary backend setup.
  • Installed Dependencies: You installed the necessary packages for backend development like express, pg (for PostgreSQL), cors, and dotenv (for environment variables).
  • Database Setup: Set up PostgreSQL as the database system, where you created a database (crm_db) and a table (customers) to store customer information.

2. Setting Up PostgreSQL Database

  • You created a PostgreSQL database (crm_db) with a customers table. The table was designed to store customer details, such as name, contact_info, and gst_number.
  • We also ran a SQL command to insert test data into the customers table.

3. Building the Backend (Express API)

  • Database Connection (db.js): A database connection was established using pg (PostgreSQL client for Node.js). We used the Client object to connect to the PostgreSQL server and handle queries.
    • Code: const client = new Client({...}); and client.connect();
  • Routes (customerRoutes.js): You defined the routes for handling customer data in the customerRoutes.js file.
    • GET /customers: To fetch all customers.
    • POST /customers: To create a new customer.
    • PUT /customers/:id: To update a customer’s details by ID.
    • DELETE /customers/:id: To delete a customer by ID.
  • Controller Functions (customerController.js): These were created to handle the logic for each route.
    • getAllCustomers: Fetch all customers from the database.
    • createCustomer: Insert a new customer into the database.
    • updateCustomer: Update a customer by their ID.
    • deleteCustomer: Delete a customer by their ID.
  • Database Queries: Inside each controller function, we used SQL queries to interact with the customers table, such as SELECT * FROM customers, INSERT INTO customers, UPDATE customers, and DELETE FROM customers.

4. Fixing Errors and Testing

  • Error Fixing: You faced a few issues:
    • db is not defined: The db module was not being imported correctly in the controller. We fixed this by ensuring that the correct import statement was used (const db = require('../db');).
    • Cannot GET /customers/2: This error was caused by the wrong routing or the ID not being passed correctly in the request. We corrected the routing and added error handling to handle missing customer IDs.
  • Database Entry: We ensured that the database had valid entries, and tested the routes after inserting some sample data.
  • Testing with Postman: You used Postman to test the routes:
    • GET /customers to fetch all customers.
    • GET /customers/:id to fetch a specific customer by ID.
    • POST /customers to add a new customer.
    • PUT /customers/:id to update a customer’s details.
    • DELETE /customers/:id to delete a customer by ID.

5. Current Status

  • The API is successfully set up with routes to handle customer data (GET, POST, PUT, DELETE).
  • You’ve handled database errors, such as handling cases where a customer ID is not found.
  • Your backend is running and handling requests for the customers' data.

Summary of What You Have Accomplished:

  1. Database Setup: Successfully set up PostgreSQL and created a customers table.
  2. API Endpoints: Created CRUD (Create, Read, Update, Delete) endpoints for managing customers.
  3. Error Handling: Managed errors like missing database connections or invalid routes.
  4. Testing: Tested the API endpoints using Postman for correct functionality.
  5. Corrected Issues: Addressed issues like missing db imports and route handling errors.

Next Steps:

  • Frontend Integration: You can now integrate this backend with a frontend (React or any other frontend framework) to display and interact with the customer data.
  • Authentication: Consider adding user authentication and authorization for secure access to the application.
  • Deployment: If everything works fine locally, you can then consider deploying the application on a server for production use.

=======

Textile-CRM

0a621102c90eb3529016ff3162d2c131b5f7566d

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published