misc_pterodactyl-panel/resources/scripts/api/admin/nests/searchEggs.ts

25 lines
749 B
TypeScript
Raw Normal View History

import http from '@/api/http';
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
interface Filters {
name?: string;
}
export default (nestId: number, filters?: Filters, include: string[] = []): Promise<Egg[]> => {
const params = {};
if (filters !== undefined) {
Object.keys(filters).forEach(key => {
// @ts-ignore
params['filter[' + key + ']'] = filters[key];
});
}
return new Promise((resolve, reject) => {
http.get(`/api/application/nests/${nestId}/eggs`, { params: { include: include.join(','), ...params } })
.then(response => resolve(
(response.data.data || []).map(rawDataToEgg)
))
.catch(reject);
});
};