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
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.
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.
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
Verified that only authorized users can edit or delete messages to maintain data integrity.
Ensured that the chat initialization, retrieval, and deletion processes are functioning as expected in development.
Future Improvements
Adding pagination and filtering for chat messages.
Implementing notifications for new messages to enhance user engagement.
Dependencies
Requires Prisma Client (prisma-client-js) and MongoDB setup with updated environment configurations.
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.
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
Chat Functionality:
createChat
function to initialize a new chat between a customer and a vendor, with an initial message.getAllChatsByVendorId
andgetAllChatsByCustomerId
functions to retrieve all chats for a specific vendor or customer.getSpecificChat
function to fetch a unique chat between a customer and a vendor for a particular dish.Message Management:
deleteMessage
function to allow users to delete their own messages, with checks for sender identity.editMessage
function to enable message updates, with validation for sender ownership of the message.Prisma Schema Enhancements:
Chat
andMessage
models, facilitating chat-based interactions:Chat
model with relations toCustomer
,Vendor
, andDish
models, ensuring that each chat is unique between a customer and vendor.Message
model with associations toChat
andCustomer
, allowing for structured message storage within a chat.@@unique([customerId, vendorId])
constraint in theChat
model to ensure one-to-one chat mapping between a customer and vendor.Category
andTag
enums, and added relations betweenCustomer
,Vendor
,Dish
, andChat
models.Error Handling
Each function implements error handling, returning a structured response with
success
,data
, anderror
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
prisma-client-js
) and MongoDB setup with updated environment configurations.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.