feat(support): complete full CRUD for support module
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const result = await support_service.createSupportIntoDB(data);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "support created successfully.",
|
||||
data: result,
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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 result = await support_service.getAllSupportFromDB(id as string, role as string, search as string, type as string, status as string);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "All support fetched successfully.",
|
||||
data: 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 result = await support_service.getSingleSupportFromDB(id as string, userId as string, role as string);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "Single support fetched successfully.",
|
||||
data: result,
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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 result = await support_service.updateSupportIntoDB(id as string, userId as string, role as string, data);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "support updated successfully.",
|
||||
data: result,
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
const delete_support = catchAsync(async (req, res) => {
|
||||
const {id} = req.params;
|
||||
const userId = req?.user?.accountId;
|
||||
const role = req?.user?.role
|
||||
|
||||
const result = await support_service.deleteSupportFromDB(id as string, userId as string, role as string);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "support deleted successfully.",
|
||||
data: result,
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
export const support_controller = {
|
||||
createSupport,
|
||||
getAllSupport,
|
||||
get_single_support,
|
||||
update_support,
|
||||
delete_support,
|
||||
};
|
||||
Reference in New Issue
Block a user