feat(support): update Swagger documentation for support endpoints
This commit is contained in:
@@ -1,17 +1,14 @@
|
|||||||
|
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import catchAsync from "../../utils/catch_async";
|
import catchAsync from "../../utils/catch_async";
|
||||||
import manageResponse from "../../utils/manage_response";
|
import manageResponse from "../../utils/manage_response";
|
||||||
import { support_service } from "./support.service";
|
import { support_service } from "./support.service";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const createSupport = catchAsync(async (req: Request, res: Response) => {
|
const createSupport = catchAsync(async (req: Request, res: Response) => {
|
||||||
const id = req?.user?.accountId;
|
const id = req?.user?.accountId;
|
||||||
const data = {
|
const data = {
|
||||||
...req.body,
|
...req.body,
|
||||||
storeAccountId: id as string
|
storeAccountId: id as string,
|
||||||
}
|
};
|
||||||
|
|
||||||
const result = await support_service.createSupportIntoDB(data);
|
const result = await support_service.createSupportIntoDB(data);
|
||||||
manageResponse(res, {
|
manageResponse(res, {
|
||||||
@@ -23,31 +20,43 @@ const createSupport = catchAsync(async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const getAllSupport = catchAsync(async (req: Request, res: Response) => {
|
const getAllSupport = catchAsync(async (req: Request, res: Response) => {
|
||||||
const role = req?.user?.role;
|
const role = req?.user?.role;
|
||||||
const id = req?.user?.accountId;
|
const id = req?.user?.accountId;
|
||||||
const search = req?.query?.search;
|
const search = req?.query?.search;
|
||||||
const type = req?.query?.type;
|
const type = req?.query?.type;
|
||||||
const status = req?.query?.status;
|
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, {
|
manageResponse(res, {
|
||||||
success: true,
|
success: true,
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
message: "All support fetched successfully.",
|
message: "All support fetched successfully.",
|
||||||
data: result,
|
data: result.data,
|
||||||
meta: {},
|
meta: result.meta,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const get_single_support = catchAsync(async (req, res) => {
|
const get_single_support = catchAsync(async (req, res) => {
|
||||||
const {id} = req.params;
|
const { id } = req.params;
|
||||||
const userId = req?.user?.accountId;
|
const userId = req?.user?.accountId;
|
||||||
const role = req?.user?.role
|
const role = req?.user?.role;
|
||||||
|
|
||||||
|
const result = await support_service.getSingleSupportFromDB(
|
||||||
const result = await support_service.getSingleSupportFromDB(id as string, userId as string, role as string);
|
id as string,
|
||||||
|
userId as string,
|
||||||
|
role as string,
|
||||||
|
);
|
||||||
manageResponse(res, {
|
manageResponse(res, {
|
||||||
success: true,
|
success: true,
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
@@ -57,15 +66,18 @@ const get_single_support = catchAsync(async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const update_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 userId = req?.user?.accountId;
|
||||||
const role = req?.user?.role;
|
const role = req?.user?.role;
|
||||||
const data = req.body
|
const data = req.body;
|
||||||
|
|
||||||
|
const result = await support_service.updateSupportIntoDB(
|
||||||
const result = await support_service.updateSupportIntoDB(id as string, userId as string, role as string, data);
|
id as string,
|
||||||
|
userId as string,
|
||||||
|
role as string,
|
||||||
|
data,
|
||||||
|
);
|
||||||
manageResponse(res, {
|
manageResponse(res, {
|
||||||
success: true,
|
success: true,
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
@@ -76,11 +88,15 @@ const update_support = catchAsync(async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const delete_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 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, {
|
manageResponse(res, {
|
||||||
success: true,
|
success: true,
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ const getAllSupportFromDB = async (
|
|||||||
search?: string,
|
search?: string,
|
||||||
type?: string,
|
type?: string,
|
||||||
status?: string,
|
status?: string,
|
||||||
|
page: number = 1,
|
||||||
|
limit: number = 10,
|
||||||
) => {
|
) => {
|
||||||
const andCondition: Prisma.SupportWhereInput[] = [];
|
const andCondition: Prisma.SupportWhereInput[] = [];
|
||||||
|
|
||||||
@@ -55,14 +57,31 @@ const getAllSupportFromDB = async (
|
|||||||
const whereCondition: Prisma.SupportWhereInput =
|
const whereCondition: Prisma.SupportWhereInput =
|
||||||
andCondition.length > 0 ? { AND: andCondition } : {};
|
andCondition.length > 0 ? { AND: andCondition } : {};
|
||||||
|
|
||||||
const result = await prisma.support.findMany({
|
const skip = (page - 1) * limit;
|
||||||
where: whereCondition,
|
|
||||||
orderBy: {
|
|
||||||
createdAt: "desc",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
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 (
|
const getSingleSupportFromDB = async (
|
||||||
@@ -125,8 +144,8 @@ const deleteSupportFromDB = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await prisma.support.delete({
|
const result = await prisma.support.delete({
|
||||||
where: {id}
|
where: { id },
|
||||||
})
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
|
export const supportSwaggerDocs = {
|
||||||
export const supportSwaggerDocs = {
|
|
||||||
"/api/support": {
|
"/api/support": {
|
||||||
post: {
|
post: {
|
||||||
tags: ["support"],
|
tags: ["support"],
|
||||||
summary: "Create new support",
|
summary: "Create new support",
|
||||||
description: "",
|
description:
|
||||||
|
"type must be: TECHNICAL | BILLING | DOMAIN | TEMPLATE | PAYMENT | ACCOUNT | FEATURE_REQUEST | BUG | OTHER",
|
||||||
requestBody: {
|
requestBody: {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
example: JSON.stringify({
|
example: JSON.stringify({
|
||||||
"issueName": "Your issue name",
|
issueName: "Your issue name",
|
||||||
"description": "Issue description",
|
description: "Issue description",
|
||||||
"type": "Issue Type"
|
type: "Issue Type",
|
||||||
}), // put your request body
|
}), // put your request body
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -39,6 +39,45 @@
|
|||||||
required: false,
|
required: false,
|
||||||
schema: { type: "number" },
|
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: {
|
responses: {
|
||||||
200: { description: "support fetched successfully" },
|
200: { description: "support fetched successfully" },
|
||||||
@@ -68,7 +107,11 @@
|
|||||||
patch: {
|
patch: {
|
||||||
tags: ["support"],
|
tags: ["support"],
|
||||||
summary: "Update 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: [
|
parameters: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
@@ -81,7 +124,14 @@
|
|||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user