From e3eae07f339d6df37c095f0c75a65d8a84734050 Mon Sep 17 00:00:00 2001 From: "tomosa.sarkar" Date: Thu, 13 Feb 2025 10:46:07 +0530 Subject: [PATCH] feat: Implemented feature of view ticket summary --- Docs/CRM.postman_collection.json | 160 ---------------------- Docs/MantisBT.postman_collection.json | 172 ------------------------ src/app/api/ticket/[ticket_id]/route.ts | 110 +++++---------- src/app/api/ticket/route.ts | 2 - src/app/home/user/view-ticket/page.tsx | 81 ++++++++++- 5 files changed, 105 insertions(+), 420 deletions(-) delete mode 100644 Docs/CRM.postman_collection.json delete mode 100644 Docs/MantisBT.postman_collection.json diff --git a/Docs/CRM.postman_collection.json b/Docs/CRM.postman_collection.json deleted file mode 100644 index b66967e..0000000 --- a/Docs/CRM.postman_collection.json +++ /dev/null @@ -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": [] - } - ] -} \ No newline at end of file diff --git a/Docs/MantisBT.postman_collection.json b/Docs/MantisBT.postman_collection.json deleted file mode 100644 index b337a5d..0000000 --- a/Docs/MantisBT.postman_collection.json +++ /dev/null @@ -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": [] - } - ] -} \ No newline at end of file diff --git a/src/app/api/ticket/[ticket_id]/route.ts b/src/app/api/ticket/[ticket_id]/route.ts index 294276c..ed6f8ad 100644 --- a/src/app/api/ticket/[ticket_id]/route.ts +++ b/src/app/api/ticket/[ticket_id]/route.ts @@ -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(request: Request, { params }: { params: { ticket_id: number }}) { + try { + const { ticket_id } = params; + const session = await getIronSession(cookies(), getSessionOptions()); + 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 ticketRepo = connection_crm.getRepository(Ticket); + // Get list of ticket raised by the user + const ticket_list = await ticketRepo.createQueryBuilder('ticket') + .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 }); + } +} -export async function GET(req: Request, { params }: { params: { ticket_id: number }}) -{ - try { - const session = await getIronSession(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); - 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) - } - catch (error) { - return Response.json(null, { status: 500 }); - } -} \ No newline at end of file diff --git a/src/app/api/ticket/route.ts b/src/app/api/ticket/route.ts index d778578..dc18ccf 100644 --- a/src/app/api/ticket/route.ts +++ b/src/app/api/ticket/route.ts @@ -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(); diff --git a/src/app/home/user/view-ticket/page.tsx b/src/app/home/user/view-ticket/page.tsx index e811f2d..fed350a 100644 --- a/src/app/home/user/view-ticket/page.tsx +++ b/src/app/home/user/view-ticket/page.tsx @@ -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([]); const [searchQuery, setSearchQuery] = useState(""); const [filteredTickets, setFilteredTickets] = useState([]); const [activeMessages, setActiveMessages] = useState(null); + const [ticketDetails, setTicketDetails] = useState(null); + const [detailsOpened, { open: openDetails, close: closeDetails }] = useDisclosure(false); + + const handleOpenDetails = async (ticketId: string) => { + try { + const response = await axios.get(`/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)} > - + @@ -101,15 +129,27 @@ export default function Page() { - + handleOpenDetails(ticket.ticket_id)} + > - + + + + + + + + + + - + )); return ( @@ -153,7 +193,7 @@ export default function Page() { - + {activeMessages?.map((msg, index) => (
+ + {ticketDetails ? ( + +
Ticket ID: {ticketDetails.ticket_id}
+
Category of Complaint: {ticketDetails.category_of_request}
+
Description: {ticketDetails.nature_of_request}
+ {/*
Additional Information: {ticketDetails.additional_info}
*/} + {/* Additional Info Table */} +
Additional Info:
+ + + {parseAdditionalInfo(ticketDetails.additional_info).map((item, index) => ( + + {item.key} + {item.value} + + ))} + +
+
Message: {ticketDetails.message}
+
Created Date: {ticketDetails.created_date}
+ +
+ ) : ( +

Loading details...

+ )} +
); }