feat(support): update Swagger documentation for support endpoints

This commit is contained in:
rahat0078
2026-04-17 00:19:22 +06:00
parent 739e3d1ad6
commit 86b2292272
3 changed files with 123 additions and 41 deletions
+34 -18
View File
@@ -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 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 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,
@@ -78,9 +90,13 @@ const update_support = catchAsync(async (req, res) => {
const delete_support = catchAsync(async (req, res) => {
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,
+24 -5
View File
@@ -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({
const skip = (page - 1) * limit;
const [data, total] = await Promise.all([
prisma.support.findMany({
where: whereCondition,
skip,
take: limit,
orderBy: {
createdAt: "desc",
},
});
}),
prisma.support.count({
where: whereCondition,
}),
]);
return result;
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;
};
+57 -10
View File
@@ -1,18 +1,18 @@
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 @@
},
},
};