2021-02-05 16:44:31 +00:00
|
|
|
import http from '@/api/http';
|
2021-02-16 05:41:19 +00:00
|
|
|
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
|
2021-02-05 16:44:31 +00:00
|
|
|
|
|
|
|
interface Filters {
|
|
|
|
name?: string;
|
|
|
|
host?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (filters?: Filters): Promise<Database[]> => {
|
2021-02-16 05:41:19 +00:00
|
|
|
const params = {};
|
2021-02-05 16:44:31 +00:00
|
|
|
if (filters !== undefined) {
|
2021-02-16 05:41:19 +00:00
|
|
|
Object.keys(filters).forEach(key => {
|
|
|
|
// @ts-ignore
|
|
|
|
params['filter[' + key + ']'] = filters[key];
|
2021-02-05 16:44:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get('/api/application/databases', { params: { ...params } })
|
|
|
|
.then(response => resolve(
|
|
|
|
(response.data.data || []).map(rawDataToDatabase)
|
|
|
|
))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|