feat: Implemented feature of view ticket summary

This commit is contained in:
Tomosa Sarkar 2025-02-13 10:46:07 +05:30
parent 41bd4ffd5f
commit e3eae07f33
5 changed files with 105 additions and 420 deletions

View File

@ -1,160 +0,0 @@
{
"info": {
"_postman_id": "c0971b0e-8469-4ffd-a95e-090b1ba552da",
"name": "CRM",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "39926215"
},
"item": [
{
"name": "Login",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"AccNo\" :\"30022497138\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "http://localhost:3000/api/auth/login/account_no"
},
"response": []
},
{
"name": "get account details",
"request": {
"auth": {
"type": "inherit",
"inherit": {}
},
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/user"
},
"response": []
},
{
"name": "Validate OTP",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"OTP\": 77208}",
"options": {
"raw": {
"language": "text"
}
}
},
"url": "http://localhost:3000/api/otp"
},
"response": []
},
{
"name": "logout",
"request": {
"auth": {
"type": "inherit",
"inherit": {}
},
"method": "POST",
"header": [],
"url": "http://localhost:3000/api/auth/logout"
},
"response": []
},
{
"name": "generate OTP",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "http://localhost:3000/api/otp"
},
"response": []
},
{
"name": "Fetch Mobile Number",
"request": {
"auth": {
"type": "inherit",
"inherit": {}
},
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/mobile_no/by/30022497139"
},
"response": []
},
{
"name": "Get User",
"request": {
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/user"
},
"response": []
},
{
"name": "Create Ticket",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"summary\":\" Login issue Related\", \r\n \"description\":\"Login related\", \r\n \r\n\t\"steps_to_reproduce\" :\"Money got debited from account\",\r\n\t\"category\": {\r\n \"name\": \"General\"\r\n\t},\r\n\t\"project\": {\r\n \"id\": 1\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "http://localhost:3000/api/ticket"
},
"response": []
},
{
"name": "Add column",
"request": {
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/addColumn"
},
"response": []
},
{
"name": "Dev populate",
"request": {
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/dev/populate"
},
"response": []
},
{
"name": "View Ticket",
"request": {
"method": "GET",
"header": [],
"url": "http://localhost:3000/api/ticket"
},
"response": []
}
]
}

View File

@ -1,172 +0,0 @@
{
"info": {
"_postman_id": "62121509-c7ee-4d92-9684-337a1d96a6ac",
"name": "MantisBT",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "39926215"
},
"item": [
{
"name": "Create Token",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "beHEFeDe-eE0YdTIK098naY0-iirvISx",
"type": "text",
"disabled": true
},
{
"key": "Authorization",
"value": "YdTsu-wuBfc4ekVDZpfk0K4dvjmoH6Z-",
"type": "text",
"disabled": true
},
{
"key": "Authorization",
"value": "DBSC0FHDatcHiScox5vm2GPuNnNrezqM",
"type": "text"
}
],
"url": {
"raw": "http://localhost/mantisBT/api/rest/users/:user_id/token",
"protocol": "http",
"host": [
"localhost"
],
"path": [
"mantisBT",
"api",
"rest",
"users",
":user_id",
"token"
],
"variable": [
{
"key": "user_id",
"value": "5",
"type": "string"
}
]
}
},
"response": []
},
{
"name": "Create issue",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "beHEFeDe-eE0YdTIK098naY0-iirvISx",
"type": "text",
"disabled": true
},
{
"key": "Authorization",
"value": "YdTsu-wuBfc4ekVDZpfk0K4dvjmoH6Z-",
"type": "text",
"disabled": true
},
{
"key": "Authorization",
"value": "GefLBxeHyHDL9DXkGqX4qQ7Cayquqdaj",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"summary\": \"ATM Fault\",\r\n \"description\": \"ATM Fault\",\r\n \"additional_information\": \"{ATM ID : 678UCBA00988, debit_card : 600226543567}\",\r\n \"steps_to_reproduce\" :\"Money got debited from account\",\r\n \"project\": {\r\n \"id\": 1\r\n }\r\n}\r\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "http://localhost/mantisBT/api/rest/issues/"
},
"response": []
},
{
"name": "get a issue by issue id",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "GefLBxeHyHDL9DXkGqX4qQ7Cayquqdaj",
"type": "text"
}
],
"url": {
"raw": "http://localhost/mantisBT/api/rest/issues/:issue_id",
"protocol": "http",
"host": [
"localhost"
],
"path": [
"mantisBT",
"api",
"rest",
"issues",
":issue_id"
],
"variable": [
{
"key": "issue_id",
"value": "43"
}
]
}
},
"response": []
},
{
"name": "post note",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "DBSC0FHDatcHiScox5vm2GPuNnNrezqM",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"text\": \"test note\",\r\n \"view_state\": {\r\n \t\"name\": \"public\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost/mantisBT/api/rest/issues/:issue_id/notes",
"protocol": "http",
"host": [
"localhost"
],
"path": [
"mantisBT",
"api",
"rest",
"issues",
":issue_id",
"notes"
],
"variable": [
{
"key": "issue_id",
"value": "43"
}
]
}
},
"response": []
}
]
}

View File

@ -1,83 +1,35 @@
import { getIronSession } from "iron-session";
import { cookies } from "next/headers";
import getSessionOptions from "@/app/api/auth/session/options";
import SessionPayload from "@/app/api/auth/session/payload";
import AppDataSource from "@/app/_data/source/app-data-source";
import { User } from "@/app/_data/entities/User";
import SessionPayload from "../../auth/session/payload";
import getSessionOptions from "../../auth/session/options";
import { Ticket } from "@/app/_data/entities/Ticket";
export async function GET(req: Request, { params }: { params: { ticket_id: number }})
{
export async function GET(request: Request, { params }: { params: { ticket_id: number }}) {
try {
const { ticket_id } = params;
const session = await getIronSession<SessionPayload>(cookies(), getSessionOptions());
console.log("Session :",session);
if (!session.TwoStepAuthentication) {
return Response.json(null);
}
if (!session.accountNo) {
return Response.json({ message: `Please sign in before raise a ticket` })
}
const connection_crm = await AppDataSource.getConnection();
//const connection_mantis = await AppDataSource.getMantisConnection();
const userRepo = connection_crm.getRepository(User);
const user_table = await userRepo.createQueryBuilder('user')
.select(['first_name', 'middle_name', 'last_name'])
.where("user.bank_account_no = :AccountNo", { AccountNo: session.accountNo })
.getRawOne();
const user_name = (user_table.first_name ? user_table.first_name + ' ' : '') +
(user_table.middle_name ? user_table.middle_name + ' ' : '') +
(user_table.last_name ? user_table.last_name + ' ' : '');
const ticketRepo = connection_crm.getRepository(Ticket);
// Get list of ticket raised by the user
const ticket_list = await ticketRepo.createQueryBuilder('ticket')
.select(['id', 'category_of_request', 'nature_of_request', 'created_date','additional_info'])
.where("ticket.created_by = :created_by", { created_by: user_name }).getRawMany();
if(!ticket_list){return Response.json('No Details Found')}
const ticket_ids = ticket_list.map(ticket => ticket.id);
// Mantis-database fetching for "status" & "message"
const queryRunner = connection_mantis.createQueryRunner();
await queryRunner.connect();
let ticketResolution: { [key: number]: string } = {};
let ticketMessage: { [key: number]: string[] } = {};
for (const id of ticket_ids) {
// For status of ticket
const ticket_resolution = await queryRunner.query('SELECT resolution,handler_id FROM "kccb_bug" WHERE id = $1', [id]);
const ticket_status =ticket_resolution[0]?.resolution
const ticket_handler =ticket_resolution[0]?.handler_id
let status :string ='';
if(ticket_status === 10 && ticket_handler === 0){status = 'Open'}
if(ticket_handler > 0){status = 'In Progress'}
if(ticket_status === 20){status='Resolved'}
if(ticket_status === 30){status='Reopen'}
ticketResolution[id] = status
// For Message of ticket
const ticket_note = await queryRunner.query('SELECT id FROM "kccb_bugnote" WHERE bug_id = $1', [id]);
const ticket_note_ids =ticket_note.map((item:{id:number}) =>item.id)
for(const note_id of ticket_note_ids ){
const ticket_note_text = await queryRunner.query('SELECT note FROM "kccb_bugnote_text" WHERE id = $1', [note_id]);
if (!ticketMessage[id]) {
ticketMessage[id] = [];
}
ticketMessage[id].push(...ticket_note_text);
}
}
const result = ticket_list.map(item =>
(
{
...item,status:ticketResolution[item.id]||null,message: ticketMessage[item.id]||null
}
)
)
queryRunner.release();
return Response.json(result)
.select(['id','ticket_id', 'category_of_request', 'nature_of_request', 'additional_info','message','created_date'])
.where("ticket.ticket_id = :ticket_id" , { ticket_id: ticket_id })
.andWhere("ticket.customer_account_no = :customer_account_no" ,{customer_account_no:session.accountNo })
.getRawOne();
if(!ticket_list){return Response.json("No Ticket is Present.");}
return Response.json(ticket_list)
}
catch (error) {
return Response.json(null, { status: 500 });
}
}

View File

@ -20,8 +20,6 @@ export async function POST(request: Request) {
if (!session.TwoStepAuthentication) {
return Response.json(null);
}
const mantisBT_Token =process.env.MantisBT_Token || ""; //MantisBT Token
const body = await request.json();

View File

@ -14,7 +14,7 @@ import {
Tooltip,
} from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import { IconEye, IconMessage, IconSearch } from "@tabler/icons-react";
import { IconEye, IconMessage, IconSearch, IconTrash } from "@tabler/icons-react";
import axios from "axios";
import { useEffect, useState } from "react";
@ -30,13 +30,41 @@ interface Ticket {
status: string;
message: Message[];
}
interface TicketDetails {
ticket_id: string;
category_of_request: string;
nature_of_request: string;
additional_info: string;
message : string;
created_date: string;
}
export default function Page() {
const [opened, { open, close }] = useDisclosure(false);
const [tickets, setTickets] = useState<Ticket[]>([]);
const [searchQuery, setSearchQuery] = useState("");
const [filteredTickets, setFilteredTickets] = useState<Ticket[]>([]);
const [activeMessages, setActiveMessages] = useState<Message[] | null>(null);
const [ticketDetails, setTicketDetails] = useState<TicketDetails| null>(null);
const [detailsOpened, { open: openDetails, close: closeDetails }] = useDisclosure(false);
const handleOpenDetails = async (ticketId: string) => {
try {
const response = await axios.get<TicketDetails>(`/api/ticket/${ticketId}`); // Assuming API provides details
setTicketDetails(response.data);
openDetails();
}
catch (error) {
console.error("Failed to fetch ticket details:", error);
}
};
// For parsing additional_info
const parseAdditionalInfo = (info: string) => {
return info.split(", ").map((item) => {
const [key, value] = item.split(": ");
return { key: key.trim(), value: value?.trim() || "" };
});
};
// Sort and filter tickets based on the time
useEffect(() => {
@ -93,7 +121,7 @@ export default function Page() {
onClick={() => handleOpenMessage(ticket.message)}
>
<Tooltip label="Message">
<IconMessage/>
<IconMessage />
</Tooltip>
</ActionIcon>
</Group>
@ -101,9 +129,21 @@ export default function Page() {
<Table.Td>
<Group>
<ActionIcon variant="subtle">
<ActionIcon variant="subtle"
onClick={() => handleOpenDetails(ticket.ticket_id)}
>
<Tooltip label="Details of the Ticket">
<IconEye/>
<IconEye />
</Tooltip>
</ActionIcon>
</Group>
</Table.Td>
<Table.Td>
<Group>
<ActionIcon variant="subtle"
>
<Tooltip label="Delete the Ticket">
<IconTrash/>
</Tooltip>
</ActionIcon>
</Group>
@ -153,7 +193,7 @@ export default function Page() {
</Table>
<Modal opened={opened} onClose={close} title="Message">
<Flex direction="column" gap="sm">
<Flex direction="column" gap="md">
{activeMessages?.map((msg, index) => (
<div
key={index}
@ -172,6 +212,33 @@ export default function Page() {
</Button>
</Flex>
</Modal>
<Modal opened={detailsOpened} onClose={closeDetails}>
{ticketDetails ? (
<Flex direction="column" gap="md">
<div><strong>Ticket ID:</strong> {ticketDetails.ticket_id}</div>
<div><strong>Category of Complaint:</strong> {ticketDetails.category_of_request}</div>
<div><strong>Description:</strong> {ticketDetails.nature_of_request}</div>
{/* <div><strong>Additional Information:</strong> {ticketDetails.additional_info}</div> */}
{/* Additional Info Table */}
<div><strong>Additional Info:</strong></div>
<Table withTableBorder withColumnBorders highlightOnHover>
<Table.Tbody>
{parseAdditionalInfo(ticketDetails.additional_info).map((item, index) => (
<Table.Tr key={index}>
<Table.Td>{item.key}</Table.Td>
<Table.Td>{item.value}</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
<div><strong>Message:</strong> {ticketDetails.message}</div>
<div><strong>Created Date:</strong> {ticketDetails.created_date}</div>
<Button onClick={closeDetails} mt="sm">Close</Button>
</Flex>
) : (
<p>Loading details...</p>
)}
</Modal>
</Container>
);
}