Skip to content

Commit

Permalink
Merge pull request #271 from shubhagarwal1/ticketr
Browse files Browse the repository at this point in the history
Implement Ticketing System API for Customer Support
  • Loading branch information
Vimall03 authored Nov 9, 2024
2 parents feee9df + 61f506e commit eac6dbd
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
Empty file.
201 changes: 201 additions & 0 deletions alimento-nextjs/actions/customer-ticket/README.md
Original file line number Diff line number Diff line change
@@ -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`).
29 changes: 29 additions & 0 deletions alimento-nextjs/actions/customer-ticket/createTicket.tsx
Original file line number Diff line number Diff line change
@@ -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' };
}
}
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions alimento-nextjs/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,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
}

0 comments on commit eac6dbd

Please sign in to comment.