add getAllProxies route
This commit is contained in:
1 parent
f731648007
commit
b2dca7b62f
6 files changed
+30
-1
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
export interface IProxiesController {
|
||||
createProxy: RequestHandler;
|
||||
getProxyById: RequestHandler;
|
||||
getAllProxies: RequestHandler;
|
||||
getProxiesByTeamId: RequestHandler;
|
||||
editProxy: RequestHandler;
|
||||
deleteProxy: RequestHandler;
|
||||
@@ -43,6 +44,15 @@ class ProxyController implements IProxiesController {
|
||||
});
|
||||
});
|
||||
|
||||
getAllProxies = catchAsync(async (req: Request, res: Response) => {
|
||||
const proxies = await this.proxiesService.getProxies();
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Proxies retrieved successfully",
|
||||
data: proxies,
|
||||
});
|
||||
});
|
||||
|
||||
getProxiesByTeamId = catchAsync(async (req: Request, res: Response) => {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const proxies = await this.proxiesService.getProxiesByTeamId(teamId);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { IProxiesController } from "@/api/controllers/proxyController.js";
|
||||
import { isAllowed } from "@/api/middleware/isAllowed.js";
|
||||
import { Router } from "express";
|
||||
|
||||
export const createProxyRoutes = (proxyController: IProxiesController): Router => {
|
||||
const router = Router();
|
||||
router.post("/", proxyController.createProxy);
|
||||
router.get("/", isAllowed(["admin", "superadmin"]), proxyController.getAllProxies);
|
||||
router.get("/team", proxyController.getProxiesByTeamId);
|
||||
router.get("/:id", proxyController.getProxyById);
|
||||
router.delete("/:id", proxyController.deleteProxy);
|
||||
|
||||
@@ -25,7 +25,7 @@ import { CheckFilter, DateRange } from "@/types/query.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { NETWORK_ERROR } from "@/types/network.js";
|
||||
|
||||
const SERVICE_NAME = "StatusService";
|
||||
const SERVICE_NAME = "ChecksRepository";
|
||||
|
||||
class MongoChecksRepository implements IChecksRepository {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
@@ -213,6 +213,9 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
};
|
||||
|
||||
private filterToMatch = (filter: CheckFilter | undefined): Record<string, unknown> => {
|
||||
if (filter === undefined) {
|
||||
return {};
|
||||
}
|
||||
switch (filter) {
|
||||
case "up":
|
||||
return { status: true };
|
||||
|
||||
@@ -4,6 +4,7 @@ export interface IProxiesRepository {
|
||||
// create
|
||||
create(proxyData: Partial<Proxy>): Promise<Proxy>;
|
||||
// read
|
||||
findAll(): Promise<Proxy[]>;
|
||||
findById(proxyId: string, teamId: string): Promise<Proxy>;
|
||||
findByIdOrNull(proxyId: string, teamId?: string): Promise<Proxy | null>;
|
||||
findByTeamId(teamId: string): Promise<Proxy[]>;
|
||||
|
||||
@@ -37,6 +37,11 @@ class MongoProxiesRepository implements IProxiesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async findAll(): Promise<Proxy[]> {
|
||||
const proxies = await ProxyModel.find();
|
||||
return proxies.map(this.toEntity);
|
||||
}
|
||||
|
||||
async findById(proxyId: string, teamId: string): Promise<Proxy> {
|
||||
const proxy = await ProxyModel.findOne({ _id: proxyId, teamId });
|
||||
if (!proxy) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ISettingsService } from "@/domain/app-settings/app-settings.service.js"
|
||||
export interface IProxiesService {
|
||||
createProxy(proxy: Partial<Proxy>, teamId: string): Promise<ProxyResponse>;
|
||||
getProxy(proxyId: string, teamId: string): Promise<ProxyResponse>;
|
||||
getProxies(): Promise<ProxyResponse[]>;
|
||||
getProxiesByTeamId(teamId: string): Promise<ProxyResponse[]>;
|
||||
updateProxy(proxyId: string, teamId: string, patch: Partial<Proxy> & { clearPassword?: boolean; clearUsername?: boolean }): Promise<ProxyResponse>;
|
||||
deleteProxy(proxyId: string, teamId: string): Promise<ProxyResponse>;
|
||||
@@ -39,6 +40,13 @@ export class ProxiesService implements IProxiesService {
|
||||
return this.toResponse(raw);
|
||||
};
|
||||
|
||||
getProxies = async (): Promise<ProxyResponse[]> => {
|
||||
const raw = await this.proxiesRepository.findAll();
|
||||
const clean = raw.map((r) => {
|
||||
return this.toResponse(r);
|
||||
});
|
||||
return clean;
|
||||
};
|
||||
getProxiesByTeamId = async (teamId: string): Promise<ProxyResponse[]> => {
|
||||
const raw = await this.proxiesRepository.findByTeamId(teamId);
|
||||
const clean = raw.map((r) => {
|
||||
|
||||
Reference in new issue
Block a user