This commit is contained in:
2025-11-18 20:47:48 +00:00
commit 747fb787e1
38 changed files with 18518 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import type { PeeringDbClient } from './peeringdb.classes.client.js';
import type { IOrganization } from './interfaces/peeringdb.api.organization.js';
import type { IQueryOptions } from './peeringdb.types.js';
/**
* Manager for Organization resources
*/
export class OrganizationManager {
constructor(private client: PeeringDbClient) {}
/**
* List organizations with optional filtering
*/
async list(options: IQueryOptions = {}): Promise<IOrganization[]> {
return this.client.request<IOrganization>('org', 'GET', options);
}
/**
* Get a single organization by ID
*/
async getById(id: number, depth?: 0 | 1 | 2): Promise<IOrganization | null> {
const options: IQueryOptions = { id };
if (depth !== undefined) {
options.depth = depth;
}
const results = await this.client.request<IOrganization>('org', 'GET', options);
return results[0] || null;
}
/**
* Search organizations by name
*/
async searchByName(name: string, options: IQueryOptions = {}): Promise<IOrganization[]> {
return this.client.request<IOrganization>('org', 'GET', {
...options,
name__contains: name,
});
}
/**
* Get organizations by country
*/
async getByCountry(country: string, options: IQueryOptions = {}): Promise<IOrganization[]> {
return this.client.request<IOrganization>('org', 'GET', {
...options,
country,
});
}
/**
* Create a new organization (requires authentication)
*/
async create(data: Partial<IOrganization>): Promise<IOrganization> {
const results = await this.client.request<IOrganization>('org', 'POST', {}, data);
return results[0];
}
/**
* Update an organization (requires authentication)
*/
async update(id: number, data: Partial<IOrganization>): Promise<IOrganization> {
const results = await this.client.request<IOrganization>(`org/${id}`, 'PUT', {}, data);
return results[0];
}
/**
* Delete an organization (requires authentication)
*/
async delete(id: number): Promise<void> {
await this.client.request('org', 'DELETE', { id });
}
}