81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
|
|
import catchAsync from "../../utils/catch_async.js";
|
||
|
|
import manageResponse from "../../utils/manage_response.js";
|
||
|
|
import { support_service } from "./support.service.js";
|
||
|
|
const createSupport = catchAsync(async (req, res) => {
|
||
|
|
const id = req?.user?.accountId;
|
||
|
|
const data = {
|
||
|
|
...req.body,
|
||
|
|
storeAccountId: id
|
||
|
|
};
|
||
|
|
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, res) => {
|
||
|
|
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, role, search, type, status);
|
||
|
|
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, userId, role);
|
||
|
|
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, userId, role, 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, userId, role);
|
||
|
|
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,
|
||
|
|
};
|