UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

104 lines (103 loc) 4.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.databaseMethods = void 0; const Functions_1 = require("../../modules/Functions"); class databaseMethods { application; constructor(application) { this.application = application; } /** * @param serverId - The server ID to get the databases from * @param options - Include information about server relationships * @returns Array of databases * @example * ```ts * const res = await app.getServersDatabase(1) // res = Database[] * ``` * @example * ```ts * app.getServersDatabase(1).then((res) => console.log(res)) // res = Database[] * ``` */ getServersDatabases = async (serverId, options) => { return this.application.request('GET', null, 'data', `/api/application/servers/${serverId}/databases${(0, Functions_1.makeOptions)({ includes: { ...options } })}`); }; /** * @param serverId - The server ID to get the database from * @param databaseId - The ID of the database * @param options - Include information about server relationships * @returns Database information * @example * ```ts * const res = await app.getServersDatabaseInfo(1, 1) // res = DatabaseAttributes * ``` * @example * ```ts * app.getServersDatabaseInfo(1, 2).then((res) => console.log(res)) // res = DatabaseAttributes * ``` */ getServersDatabaseInfo = async (serverId, databaseId, options) => { return this.application.request('GET', null, 'attributes', `/api/application/servers/${serverId}/databases/${databaseId}${(0, Functions_1.makeOptions)({ includes: { ...options } })}`); }; /** * @param name - Name of the Database * @param dbHostId - ID of the Database Host * @param serverId - The server ID to create the database in * @param allowedIp - IP allowed to connect, leave "%" if you dont want to restrict * @param options - Include information about server relationships * @returns Information about the new database * @example * ```ts * const res = await app.createDatabase('DATABASE_1', 1, 1) // res = DatabaseAttributes * ``` * @example * ```ts * app.createDatabase('DATABASE_1', 1, 1).then((res) => console.log(res)) // res = DatabaseAttributes * ``` */ createDatabase = async (name, dbHostId, serverId, allowedIp = '%', options) => { return this.application.request('POST', { database: name, remote: allowedIp, host: dbHostId }, 'attributes', `/api/application/servers/${serverId}/databases${(0, Functions_1.makeOptions)({ includes: { ...options } })}`); }; /** * @param serverId - The server ID to get the database from * @param databaseId - The ID of the database * @returns If successful returns Successfully reset the password! * @example * ```ts * const res = await app.resetDatabasePassword(1, 1) // res = Successfully reset the password! * ``` * @example * ```ts * app.resetDatabasePassword(1, 2).then((res) => console.log(res)) // res = Successfully reset the password! * ``` */ resetDatabasePassword = async (serverId, databaseId) => { return this.application.request('POST', null, 'Successfully reset the password!', `/api/application/servers/${serverId}/databases/${databaseId}/reset-password`); }; /** * @param serverId - The server ID to delete the database in * @param databaseId - The ID of the database * @returns If successful returns Successfully deleted the database! * @example * ```ts * const res = await app.resetDatabasePassword(1, 1) // res = Successfully deleted the database! * ``` * @example * ```ts * app.resetDatabasePassword(1, 2).then((res) => console.log(res)) // res = Successfully deleted the database! * ``` */ deleteDatabase = async (serverId, databaseId) => { return this.application.request('DELETE', null, 'Successfully deleted the database!', `/api/application/servers/${serverId}/databases/${databaseId}`); }; } exports.databaseMethods = databaseMethods;