From 86b229227273f3cbe6c0cddc35fe9a61c6f990c7 Mon Sep 17 00:00:00 2001 From: rahat0078 Date: Fri, 17 Apr 2026 00:19:22 +0600 Subject: [PATCH] feat(support): update Swagger documentation for support endpoints --- src/app/modules/support/support.controller.ts | 58 ++++++++++------ src/app/modules/support/support.service.ts | 37 +++++++--- src/app/modules/support/support.swagger.ts | 69 ++++++++++++++++--- 3 files changed, 123 insertions(+), 41 deletions(-) diff --git a/src/app/modules/support/support.controller.ts b/src/app/modules/support/support.controller.ts index 25faf3f..cffec65 100644 --- a/src/app/modules/support/support.controller.ts +++ b/src/app/modules/support/support.controller.ts @@ -1,17 +1,14 @@ - import { Request, Response } from "express"; import catchAsync from "../../utils/catch_async"; import manageResponse from "../../utils/manage_response"; import { support_service } from "./support.service"; - - const createSupport = catchAsync(async (req: Request, res: Response) => { const id = req?.user?.accountId; const data = { ...req.body, - storeAccountId: id as string - } + storeAccountId: id as string, + }; const result = await support_service.createSupportIntoDB(data); manageResponse(res, { @@ -23,31 +20,43 @@ const createSupport = catchAsync(async (req: Request, res: Response) => { }); }); - const getAllSupport = catchAsync(async (req: Request, res: Response) => { const role = req?.user?.role; const id = req?.user?.accountId; const search = req?.query?.search; const type = req?.query?.type; const status = req?.query?.status; + const page = Number(req?.query?.page) || 1; + const limit = Number(req?.query?.limit) || 10; - const result = await support_service.getAllSupportFromDB(id as string, role as string, search as string, type as string, status as string); + const result = await support_service.getAllSupportFromDB( + id as string, + role as string, + search as string, + type as string, + status as string, + page, + limit + ); manageResponse(res, { success: true, statusCode: 200, message: "All support fetched successfully.", - data: result, - meta: {}, + data: result.data, + meta: result.meta, }); }); const get_single_support = catchAsync(async (req, res) => { - const {id} = req.params; + const { id } = req.params; const userId = req?.user?.accountId; - const role = req?.user?.role + const role = req?.user?.role; - - const result = await support_service.getSingleSupportFromDB(id as string, userId as string, role as string); + const result = await support_service.getSingleSupportFromDB( + id as string, + userId as string, + role as string, + ); manageResponse(res, { success: true, statusCode: 200, @@ -57,15 +66,18 @@ const get_single_support = catchAsync(async (req, res) => { }); }); - const update_support = catchAsync(async (req, res) => { - const {id} = req.params; + const { id } = req.params; const userId = req?.user?.accountId; const role = req?.user?.role; - const data = req.body + const data = req.body; - - const result = await support_service.updateSupportIntoDB(id as string, userId as string, role as string, data); + const result = await support_service.updateSupportIntoDB( + id as string, + userId as string, + role as string, + data, + ); manageResponse(res, { success: true, statusCode: 200, @@ -76,11 +88,15 @@ const update_support = catchAsync(async (req, res) => { }); const delete_support = catchAsync(async (req, res) => { - const {id} = req.params; + const { id } = req.params; const userId = req?.user?.accountId; - const role = req?.user?.role + const role = req?.user?.role; - const result = await support_service.deleteSupportFromDB(id as string, userId as string, role as string); + const result = await support_service.deleteSupportFromDB( + id as string, + userId as string, + role as string, + ); manageResponse(res, { success: true, statusCode: 200, diff --git a/src/app/modules/support/support.service.ts b/src/app/modules/support/support.service.ts index c970fbe..c9af584 100644 --- a/src/app/modules/support/support.service.ts +++ b/src/app/modules/support/support.service.ts @@ -13,6 +13,8 @@ const getAllSupportFromDB = async ( search?: string, type?: string, status?: string, + page: number = 1, + limit: number = 10, ) => { const andCondition: Prisma.SupportWhereInput[] = []; @@ -55,14 +57,31 @@ const getAllSupportFromDB = async ( const whereCondition: Prisma.SupportWhereInput = andCondition.length > 0 ? { AND: andCondition } : {}; - const result = await prisma.support.findMany({ - where: whereCondition, - orderBy: { - createdAt: "desc", - }, - }); + const skip = (page - 1) * limit; - return result; + const [data, total] = await Promise.all([ + prisma.support.findMany({ + where: whereCondition, + skip, + take: limit, + orderBy: { + createdAt: "desc", + }, + }), + prisma.support.count({ + where: whereCondition, + }), + ]); + + return { + meta: { + page, + limit, + total, + totalPage: Math.ceil(total / limit), + }, + data, + }; }; const getSingleSupportFromDB = async ( @@ -125,8 +144,8 @@ const deleteSupportFromDB = async ( } const result = await prisma.support.delete({ - where: {id} - }) + where: { id }, + }); return result; }; diff --git a/src/app/modules/support/support.swagger.ts b/src/app/modules/support/support.swagger.ts index a4fe40d..8c5ab4b 100644 --- a/src/app/modules/support/support.swagger.ts +++ b/src/app/modules/support/support.swagger.ts @@ -1,18 +1,18 @@ - - export const supportSwaggerDocs = { +export const supportSwaggerDocs = { "/api/support": { post: { tags: ["support"], summary: "Create new support", - description: "", + description: + "type must be: TECHNICAL | BILLING | DOMAIN | TEMPLATE | PAYMENT | ACCOUNT | FEATURE_REQUEST | BUG | OTHER", requestBody: { required: true, content: { "application/json": { example: JSON.stringify({ - "issueName": "Your issue name", - "description": "Issue description", - "type": "Issue Type" + issueName: "Your issue name", + description: "Issue description", + type: "Issue Type", }), // put your request body }, }, @@ -39,6 +39,45 @@ required: false, schema: { type: "number" }, }, + { + name: "search", + in: "query", + required: false, + description: "Search by issue name or description", + schema: { + type: "string", + }, + }, + { + name: "type", + in: "query", + required: false, + description: "Filter by support type", + schema: { + type: "string", + enum: [ + "TECHNICAL", + "BILLING", + "DOMAIN", + "TEMPLATE", + "PAYMENT", + "ACCOUNT", + "FEATURE_REQUEST", + "BUG", + "OTHER", + ], + }, + }, + { + name: "status", + in: "query", + required: false, + description: "Filter by support status", + schema: { + type: "string", + enum: ["OPEN", "IN_PROGRESS", "RESOLVED", "REJECTED"], + }, + }, ], responses: { 200: { description: "support fetched successfully" }, @@ -68,7 +107,11 @@ patch: { tags: ["support"], summary: "Update support", - description: "", + description: `type(enum): TECHNICAL | BILLING | DOMAIN | TEMPLATE | PAYMENT | ACCOUNT | FEATURE_REQUEST | BUG | OTHER \n + status(enum): OPEN + | IN_PROGRESS + | RESOLVED + | REJECTED`, parameters: [ { name: "id", @@ -81,7 +124,14 @@ required: true, content: { "application/json": { - example: JSON.stringify({}), // put your request body + example: JSON.stringify({ + issueName: "Your issue name", + description: "Issue description", + type: "Issue Type", + status: "issue current status", + resolvedBy: "dataTime()", + resolvedAt: "dateTime()", + }), // put your request body }, }, }, @@ -109,6 +159,3 @@ }, }, }; - - - \ No newline at end of file