add getAllProxies route
This commit is contained in:
1 parent
f731648007
commit
b2dca7b62f
6 files changed
+30
-1
No files matched your search
@@ -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