add proxy routes/controller
This commit is contained in:
1 parent
54690fc73c
commit
1b2d2887af
4 files changed
+97
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { Request, Response, RequestHandler } from "express";
|
||||
import { catchAsync } from "@/utils/catchAsync.js";
|
||||
import { IProxiesService } from "@/domain/proxies/proxy.service.js";
|
||||
import { requireTeamId } from "./controllerUtils.js";
|
||||
import {
|
||||
createProxyBodyValidation,
|
||||
editProxyBodyValidation,
|
||||
getProxyByIdParamValidation,
|
||||
editProxyParamValidation,
|
||||
deleteProxyParamValidation,
|
||||
} from "@/api/validation/index.js";
|
||||
|
||||
export interface IProxiesController {
|
||||
createProxy: RequestHandler;
|
||||
getProxyById: RequestHandler;
|
||||
getProxiesByTeamId: RequestHandler;
|
||||
editProxy: RequestHandler;
|
||||
deleteProxy: RequestHandler;
|
||||
}
|
||||
|
||||
class ProxyController implements IProxiesController {
|
||||
constructor(private proxiesService: IProxiesService) {}
|
||||
|
||||
createProxy = catchAsync(async (req: Request, res: Response) => {
|
||||
const validatedBody = createProxyBodyValidation.parse(req.body);
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
|
||||
const proxy = await this.proxiesService.createProxy(validatedBody, teamId);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxy created successfully",
|
||||
data: proxy,
|
||||
});
|
||||
});
|
||||
getProxyById = catchAsync(async (req: Request, res: Response) => {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const { id: proxyId } = getProxyByIdParamValidation.parse(req.params);
|
||||
const proxy = await this.proxiesService.getProxy(proxyId, teamId);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxy retrieved successfully",
|
||||
data: proxy,
|
||||
});
|
||||
});
|
||||
|
||||
getProxiesByTeamId = catchAsync(async (req: Request, res: Response) => {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const proxies = await this.proxiesService.getProxiesByTeamId(teamId);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxies retrieved successfully",
|
||||
data: proxies,
|
||||
});
|
||||
});
|
||||
|
||||
editProxy = catchAsync(async (req: Request, res: Response) => {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const { id: proxyId } = editProxyParamValidation.parse(req.params);
|
||||
const validatedBody = editProxyBodyValidation.parse(req.body);
|
||||
const updatedProxy = await this.proxiesService.updateProxy(proxyId, teamId, validatedBody);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxy updated successfully",
|
||||
data: updatedProxy,
|
||||
});
|
||||
});
|
||||
|
||||
deleteProxy = catchAsync(async (req: Request, res: Response) => {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const { id: proxyId } = deleteProxyParamValidation.parse(req.params);
|
||||
await this.proxiesService.deleteProxy(proxyId, teamId);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxy deleted successfully",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default ProxyController;
|
||||
Reference in new issue
Block a user