From b0821b1fde54bbc052db20a25bdffac0759fd0dd Mon Sep 17 00:00:00 2001 From: MIGHTY1o1 Date: Sat, 9 Nov 2024 19:18:01 +0530 Subject: [PATCH 1/2] add modal for ticket system --- alimento-nextjs/prisma/schema.prisma | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/alimento-nextjs/prisma/schema.prisma b/alimento-nextjs/prisma/schema.prisma index c0bf5d8..4e67682 100644 --- a/alimento-nextjs/prisma/schema.prisma +++ b/alimento-nextjs/prisma/schema.prisma @@ -110,3 +110,24 @@ model Order { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } + + +model Ticket { + id String @id @default(uuid()) @map("_id") + customerId String + customer Customer @relation(fields: [customerId], references: [id]) + + title String + description String + status TicketStatus @default(PENDING) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + +enum TicketStatus { + PENDING + IN_PROGRESS + RESOLVED + CLOSED +} From 61f506e92db2e5a7c42d132ef42f585a422bab30 Mon Sep 17 00:00:00 2001 From: MIGHTY1o1 Date: Sat, 9 Nov 2024 19:24:37 +0530 Subject: [PATCH 2/2] add modal + backend apis for ticketing --- .../actions/customer-ticket/DeleteTicket.tsx | 0 .../actions/customer-ticket/README.md | 201 ++++++++++++++++++ .../actions/customer-ticket/createTicket.tsx | 29 +++ .../actions/customer-ticket/getAllTickets.tsx | 0 .../actions/customer-ticket/updateTicket.tsx | 0 5 files changed, 230 insertions(+) create mode 100644 alimento-nextjs/actions/customer-ticket/DeleteTicket.tsx create mode 100644 alimento-nextjs/actions/customer-ticket/README.md create mode 100644 alimento-nextjs/actions/customer-ticket/createTicket.tsx create mode 100644 alimento-nextjs/actions/customer-ticket/getAllTickets.tsx create mode 100644 alimento-nextjs/actions/customer-ticket/updateTicket.tsx diff --git a/alimento-nextjs/actions/customer-ticket/DeleteTicket.tsx b/alimento-nextjs/actions/customer-ticket/DeleteTicket.tsx new file mode 100644 index 0000000..e69de29 diff --git a/alimento-nextjs/actions/customer-ticket/README.md b/alimento-nextjs/actions/customer-ticket/README.md new file mode 100644 index 0000000..9c8ce51 --- /dev/null +++ b/alimento-nextjs/actions/customer-ticket/README.md @@ -0,0 +1,201 @@ +# Ticketing System API Documentation + +This document describes the API for the Ticketing System, where customers can raise tickets, view their existing tickets, update ticket status, and delete tickets. + +## Table of Contents + +1. [Create a Ticket](#create-a-ticket) +2. [Get Customer Tickets](#get-customer-tickets) +3. [Update Ticket Status](#update-ticket-status) +4. [Delete a Ticket](#delete-a-ticket) +5. [Response Format](#response-format) + +--- + +## 1. Create a Ticket + +### Endpoint + +- **Method**: `POST` +- **URL**: `/api/ticket` +- **Description**: This API allows a customer to raise a new ticket. + +### Request Body + +```json +{ + "customerId": "string", // The ID of the customer raising the ticket + "title": "string", // Title of the ticket + "description": "string" // Detailed description of the issue +} +``` + +### Example Request + +```typescript +const response = await createTicket({ + customerId: 'customer-id', + title: 'Issue with Dish Ordering', + description: 'I am facing issues while placing an order for my dish.' +}) +``` + +### Response + +```json +{ + "success": true | false, + "error": "Error message" // Only present if success is false +} +``` + +--- + +## 2. Get Customer Tickets + +### Endpoint + +- **Method**: `GET` +- **URL**: `/api/ticket/{customerId}` +- **Description**: This API retrieves all tickets raised by a customer. + +### Request + +- **URL Parameters**: + - `customerId`: The ID of the customer whose tickets are to be fetched. + +### Example Request + +```typescript +const response = await getCustomerTickets({ customerId: 'customer-id' }) +``` + +### Response + +```json +{ + "success": true | false, + "data": [ + { + "id": "ticket-id", + "customerId": "customer-id", + "title": "Issue with Dish Ordering", + "description": "I am facing issues while placing an order for my dish.", + "status": "PENDING", + "createdAt": "timestamp", + "updatedAt": "timestamp" + } + ], + "error": "Error message" // Only present if success is false +} +``` + +--- + +## 3. Update Ticket Status + +### Endpoint + +- **Method**: `PATCH` +- **URL**: `/api/ticket/{ticketId}` +- **Description**: This API allows updating the status of an existing ticket. + +### Request Body + +```json +{ + "status": "PENDING" | "IN_PROGRESS" | "RESOLVED" | "CLOSED" +} +``` + +### Example Request + +```typescript +const response = await updateTicketStatus({ + ticketId: 'ticket-id', + status: 'IN_PROGRESS' +}) +``` + +### Response + +```json +{ + "success": true | false, + "error": "Error message" // Only present if success is false +} +``` + +--- + +## 4. Delete a Ticket + +### Endpoint + +- **Method**: `DELETE` +- **URL**: `/api/ticket/{ticketId}` +- **Description**: This API allows deleting a specific ticket by its `ticketId`. + +### Request + +- **URL Parameters**: + - `ticketId`: The ID of the ticket to be deleted. + +### Example Request + +```typescript +const response = await deleteTicket({ ticketId: 'ticket-id' }) +``` + +### Response + +```json +{ + "success": true | false, + "error": "Error message" // Only present if success is false +} +``` + +--- + +## Response Format + +All responses from the API will follow the structure below: + +### Success Response + +```json +{ + "success": true +} +``` + +### Error Response + +```json +{ + "success": false, + "error": "Error message describing the issue" +} +``` + +--- + +## Error Handling + +If an error occurs while processing any of the API requests, the response will include a `success: false` flag and an error message. + +### Example: + +```json +{ + "success": false, + "error": "Error creating ticket" +} +``` + +--- + +## Conclusion + +This Ticketing System allows customers to raise and manage their support tickets. It includes functionality to create, read, update, and delete tickets, and track their status through various stages (`PENDING`, `IN_PROGRESS`, `RESOLVED`, `CLOSED`). diff --git a/alimento-nextjs/actions/customer-ticket/createTicket.tsx b/alimento-nextjs/actions/customer-ticket/createTicket.tsx new file mode 100644 index 0000000..824d94a --- /dev/null +++ b/alimento-nextjs/actions/customer-ticket/createTicket.tsx @@ -0,0 +1,29 @@ +'use server'; + +import prismadb from '@/lib/prismadb'; + +export async function createTicket({ + customerId, + title, + description, +}: { + customerId: string; + title: string; + description: string; +}): Promise<{ success: boolean; error?: string }> { + try { + // Create a new ticket for the customer + await prismadb.ticket.create({ + data: { + customerId, + title, + description, + }, + }); + + return { success: true }; + } catch (error) { + console.error('[CREATE_TICKET_ERROR]', error); + return { success: false, error: 'Error creating ticket' }; + } +} diff --git a/alimento-nextjs/actions/customer-ticket/getAllTickets.tsx b/alimento-nextjs/actions/customer-ticket/getAllTickets.tsx new file mode 100644 index 0000000..e69de29 diff --git a/alimento-nextjs/actions/customer-ticket/updateTicket.tsx b/alimento-nextjs/actions/customer-ticket/updateTicket.tsx new file mode 100644 index 0000000..e69de29