jspteroapi
Version:
A pterodactyl v1 api using undici
114 lines (113 loc) • 4.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.locationMethods = void 0;
const Functions_1 = require("../../modules/Functions");
class locationMethods {
application;
constructor(application) {
this.application = application;
}
/**
* @internal
*/
getLocations = async (options) => {
return this.application.request('GET', null, '', `/api/application/locations${(0, Functions_1.makeOptions)(options)}`);
};
/**
* @param options - Include information about locations relationships
* @param filter - Filter Location by specific fields and values
* @returns Array of locations
* @example
* ```ts
* const res = await app.getAllLocations() // res = Location[]
* ```
* @example
* ```ts
* app.getAllLocations().then((res) => console.log(res)) // res = Location[]
* ```
*/
getAllLocations = async (options, filter) => {
return await (0, Functions_1.paginate)(this.getLocations.bind(this), {
includes: { ...options },
filter
});
};
/**
* @param locationId - The location id to get information about
* @param options - Include information about locations relationships
* @returns Location information
* @example
* ```ts
* const res = await app.getLocationInfo(1) // res = LocationAttributes
* ```
* @example
* ```ts
* app.getLocationInfo(1).then((res) => console.log(res)) // res = LocationAttributes
* ```
*/
getLocationInfo = async (locationId, options) => {
return this.application.request('GET', null, 'attributes', `/api/application/locations/${locationId}${(0, Functions_1.makeOptions)({
includes: { ...options }
})}`);
};
/**
* @param shortName - The short name of the new location
* @param description - The description of location
* @param options - Include information about locations relationships
* @returns Location information
* @example
* ```ts
* const res = await app.createLocation('Home') // res = LocationAttributes
* ```
* @example
* ```ts
* app.createLocation('Home').then((res) => console.log(res)) // res = LocationAttributes
* ```
*/
createLocation = async (shortName, description, options) => {
return this.application.request('POST', {
short: shortName,
long: description ? description : ''
}, 'attributes', `/api/application/locations${(0, Functions_1.makeOptions)({
includes: { ...options }
})}`);
};
/**
* @param locationId - The location id to edit
* @param options - Location edit options
* @returns Location information
* @example
* ```ts
* const res = await app.editLocation(1, 'Homie') // res = LocationAttributes
* ```
* @example
* ```ts
* app.editLocation(1, undefined, 'Very good locaiton').then((res) => console.log(res)) // res = LocationAttributes
* ```
*/
editLocation = async (locationId, options) => {
const location = await this.getLocationInfo(locationId);
return this.application.request('PATCH', {
short: options.shortName ?? location.short,
long: options.description ?? location.long
}, 'attributes', `/api/application/locations/${locationId}${(0, Functions_1.makeOptions)({
includes: { ...options.options }
})}`);
};
/**
* @param locationId - The location id to delete
* @returns Successfully deleted the location!
* @example
* ```ts
* const res = await app.deleteLocation(1) // res = Successfully deleted the location!
* ```
* @example
* ```ts
* app.deleteLocation(1).then((res) => console.log(res)) // res = Successfully deleted the location!
* ```
*/
deleteLocation = async (locationId) => {
return this.application.request('DELETE', null, 'Successfully deleted the location!', `/api/application/locations/${locationId}`);
};
}
exports.locationMethods = locationMethods;