misc_pterodactyl-panel/resources/scripts/api/admin/databases/searchDatabases.ts

24 lines
686 B
TypeScript
Raw Normal View History

import http from '@/api/http';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
interface Filters {
name?: string;
host?: string;
}
export default (filters?: Filters): Promise<Database[]> => {
const params = {};
if (filters !== undefined) {
Object.keys(filters).forEach(key => {
2023-01-12 19:45:07 +00:00
// @ts-expect-error todo
params['filter[' + key + ']'] = filters[key];
});
}
return new Promise((resolve, reject) => {
http.get('/api/application/databases', { params })
2023-01-12 19:31:47 +00:00
.then(response => resolve((response.data.data || []).map(rawDataToDatabase)))
.catch(reject);
});
};