add proxy resolver
This commit is contained in:
1 parent
cd520dacc5
commit
a56bff2305
4 files changed
+126
-1
No files matched your search
@@ -5,6 +5,7 @@ export interface IProxiesRepository {
|
||||
create(proxyData: Partial<Proxy>): Promise<Proxy>;
|
||||
// read
|
||||
findById(proxyId: string, teamId: string): Promise<Proxy>;
|
||||
findByIdOrNull(proxyId: string, teamId?: string): Promise<Proxy | null>;
|
||||
findByTeamId(teamId: string): Promise<Proxy[]>;
|
||||
// update
|
||||
updateById(proxyId: string, teamId: string, patch: Partial<Proxy>, options?: { unsetPassword?: boolean; unsetUsername?: boolean }): Promise<Proxy>;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Proxy } from "@/domain/proxies/proxy.type.js";
|
||||
import { ProxyDocument, ProxyModel } from "@/domain/proxies/proxy.model.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { toStringId, toDateString } from "@/utils/mongoMappers.js";
|
||||
import { UpdateQuery } from "mongoose";
|
||||
import { Error as MongooseError, UpdateQuery } from "mongoose";
|
||||
|
||||
const SERVICE_NAME = "ProxiesRepository";
|
||||
|
||||
@@ -45,6 +45,18 @@ class MongoProxiesRepository implements IProxiesRepository {
|
||||
return this.toEntity(proxy);
|
||||
}
|
||||
|
||||
async findByIdOrNull(proxyId: string, teamId?: string): Promise<Proxy | null> {
|
||||
try {
|
||||
const proxy = await ProxyModel.findOne(teamId ? { _id: proxyId, teamId } : { _id: proxyId });
|
||||
return proxy ? this.toEntity(proxy) : null;
|
||||
} catch (error) {
|
||||
if (error instanceof MongooseError.CastError) {
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async findByTeamId(teamId: string): Promise<Proxy[]> {
|
||||
const proxies = await ProxyModel.find({ teamId });
|
||||
return proxies.map(this.toEntity);
|
||||
|
||||
Reference in new issue
Block a user