UNPKG

pterowrap

Version:

A node.js wrapper for Pterodactyl API

52 lines (51 loc) 1.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Allocation_1 = __importDefault(require("../../../structures/client/server/Allocation")); class AllocationManager { constructor(client, _parentServer) { this.client = client; this._parentServer = _parentServer; } list(options = {}) { return new Promise(async (resolve, reject) => { try { const list = await this.client.call({ endpoint: `servers/${this._parentServer.identifier}/network/allocations`, parameters: options }); const r = []; for (let i = 0; i < list.data.length; i++) { r.push(new Allocation_1.default(this.client, list.data[i], this._parentServer)); } resolve(r); } catch (e) { reject(e); } }); } get(id, options = {}) { return new Promise(async (resolve, reject) => { try { const allocations = await this.list(options); const found = allocations.find((a) => a.id === id) || null; resolve(found); } catch (e) { reject(e); } }); } assign() { return new Promise(async (resolve, reject) => { try { const data = await this.client.call({ endpoint: `servers/${this._parentServer.identifier}/network/allocations`, method: "POST" }); resolve(new Allocation_1.default(this.client, data, this._parentServer)); } catch (e) { reject(e); } }); } } exports.default = AllocationManager;