initial
This commit is contained in:
92
ts/peeringdb.classes.facilitymanager.ts
Normal file
92
ts/peeringdb.classes.facilitymanager.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import type { PeeringDbClient } from './peeringdb.classes.client.js';
|
||||
import type { IFacility } from './interfaces/peeringdb.api.facility.js';
|
||||
import type { IQueryOptions } from './peeringdb.types.js';
|
||||
|
||||
/**
|
||||
* Manager for Facility resources
|
||||
*/
|
||||
export class FacilityManager {
|
||||
constructor(private client: PeeringDbClient) {}
|
||||
|
||||
/**
|
||||
* List facilities with optional filtering
|
||||
*/
|
||||
async list(options: IQueryOptions = {}): Promise<IFacility[]> {
|
||||
return this.client.request<IFacility>('fac', 'GET', options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single facility by ID
|
||||
*/
|
||||
async getById(id: number, depth?: 0 | 1 | 2): Promise<IFacility | null> {
|
||||
const options: IQueryOptions = { id };
|
||||
if (depth !== undefined) {
|
||||
options.depth = depth;
|
||||
}
|
||||
const results = await this.client.request<IFacility>('fac', 'GET', options);
|
||||
return results[0] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search facilities by name
|
||||
*/
|
||||
async searchByName(name: string, options: IQueryOptions = {}): Promise<IFacility[]> {
|
||||
return this.client.request<IFacility>('fac', 'GET', {
|
||||
...options,
|
||||
name__contains: name,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get facilities by country
|
||||
*/
|
||||
async getByCountry(country: string, options: IQueryOptions = {}): Promise<IFacility[]> {
|
||||
return this.client.request<IFacility>('fac', 'GET', {
|
||||
...options,
|
||||
country,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get facilities by city
|
||||
*/
|
||||
async getByCity(city: string, options: IQueryOptions = {}): Promise<IFacility[]> {
|
||||
return this.client.request<IFacility>('fac', 'GET', {
|
||||
...options,
|
||||
city__contains: city,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get facilities by organization ID
|
||||
*/
|
||||
async getByOrgId(orgId: number, options: IQueryOptions = {}): Promise<IFacility[]> {
|
||||
return this.client.request<IFacility>('fac', 'GET', {
|
||||
...options,
|
||||
org_id: orgId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new facility (requires authentication)
|
||||
*/
|
||||
async create(data: Partial<IFacility>): Promise<IFacility> {
|
||||
const results = await this.client.request<IFacility>('fac', 'POST', {}, data);
|
||||
return results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a facility (requires authentication)
|
||||
*/
|
||||
async update(id: number, data: Partial<IFacility>): Promise<IFacility> {
|
||||
const results = await this.client.request<IFacility>(`fac/${id}`, 'PUT', {}, data);
|
||||
return results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a facility (requires authentication)
|
||||
*/
|
||||
async delete(id: number): Promise<void> {
|
||||
await this.client.request('fac', 'DELETE', { id });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user