swarooppatilx / scruter

Scruter is a local classifieds and community site designed to bring people together for buying, selling, and exchanging goods and services.
https://scruter.vercel.app
GNU General Public License v3.0
28 stars 135 forks source link

Chat and Message Functionality with Schema Enhancements #538

Closed ShivanshPlays closed 1 week ago

ShivanshPlays commented 1 week ago

PR Description: Chat and Message Functionality with Schema Enhancements

Fixes #532

Overview

This pull request introduces chat and message management features, enabling customers and vendors to communicate within the application. These changes include functions for creating, fetching, editing, and deleting messages and chats, alongside necessary schema updates in Prisma for chat and message relationships.

Key Changes

  1. Chat Functionality:

    • Implemented createChat function to initialize a new chat between a customer and a vendor, with an initial message.
    • Added getAllChatsByVendorId and getAllChatsByCustomerId functions to retrieve all chats for a specific vendor or customer.
    • Developed getSpecificChat function to fetch a unique chat between a customer and a vendor for a particular dish.
  2. Message Management:

    • Created deleteMessage function to allow users to delete their own messages, with checks for sender identity.
    • Developed editMessage function to enable message updates, with validation for sender ownership of the message.
  3. Prisma Schema Enhancements:

    • Updated Prisma schema to define relationships for Chat and Message models, facilitating chat-based interactions:
      • Added Chat model with relations to Customer, Vendor, and Dish models, ensuring that each chat is unique between a customer and vendor.
      • Defined Message model with associations to Chat and Customer, allowing for structured message storage within a chat.
    • Introduced @@unique([customerId, vendorId]) constraint in the Chat model to ensure one-to-one chat mapping between a customer and vendor.
    • Enhanced the schema with Category and Tag enums, and added relations between Customer, Vendor, Dish, and Chat models.

Error Handling

Each function implements error handling, returning a structured response with success, data, and error fields to ensure consistent and clear API responses across all operations.

Database

Utilizes MongoDB as the primary database with Prisma as the ORM, aligning with the project requirements for scalability and reliability.

Testing & Validation

Future Improvements

Dependencies


This PR establishes the foundation for in-app communication between users, with robust error handling, schema alignment, and response consistency to support smooth functionality and user experience.

vercel[bot] commented 1 week ago

@ShivanshPlays is attempting to deploy a commit to the Piyush's projects Team on Vercel.

A member of the Team first needs to authorize it.