2019-07-10 04:25:57 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
|
|
|
export interface ServerDatabase {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
username: string;
|
|
|
|
connectionString: string;
|
|
|
|
allowConnectionsFrom: string;
|
|
|
|
password?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const rawDataToServerDatabase = (data: any): ServerDatabase => ({
|
|
|
|
id: data.id,
|
|
|
|
name: data.name,
|
|
|
|
username: data.username,
|
|
|
|
connectionString: `${data.host.address}:${data.host.port}`,
|
|
|
|
allowConnectionsFrom: data.connections_from,
|
2022-09-17 18:50:40 +00:00
|
|
|
password: data.relationships.password?.attributes?.password,
|
2019-07-10 04:25:57 +00:00
|
|
|
});
|
|
|
|
|
2020-07-05 01:30:50 +00:00
|
|
|
export default (uuid: string, includePassword = true): Promise<ServerDatabase[]> => {
|
2019-07-10 04:25:57 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get(`/api/client/servers/${uuid}/databases`, {
|
|
|
|
params: includePassword ? { include: 'password' } : undefined,
|
|
|
|
})
|
2022-06-26 19:13:52 +00:00
|
|
|
.then((response) =>
|
|
|
|
resolve((response.data.data || []).map((item: any) => rawDataToServerDatabase(item.attributes)))
|
|
|
|
)
|
2019-07-10 04:25:57 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|