Migrate last of the SFC's to TS files

This commit is contained in:
Dane Everitt 2019-02-09 18:46:06 -08:00
parent 5cb57af193
commit 40aa3da5de
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
9 changed files with 291 additions and 251 deletions

View file

@ -0,0 +1,30 @@
import http from '@/api/http';
// @ts-ignore
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
import {AxiosError} from "axios";
import {ServerDatabase} from "@/api/server/types";
/**
* Creates a new database on the system for the currently active server.
*/
export function createDatabase(server: string, database: string, remote: string): Promise<ServerDatabase> {
return new Promise((resolve, reject) => {
http.post(route('api.client.servers.databases', { server }), {database, remote})
.then(response => {
const copy: any = response.data.attributes;
copy.password = copy.relationships.password.attributes.password;
copy.showPassword = false;
delete copy.relationships;
resolve(copy);
})
.catch((err: AxiosError) => {
if (err.response && err.response.data && Array.isArray(err.response.data.errors)) {
return reject(err.response.data.errors[0].detail);
}
return reject(err);
});
});
}

View file

@ -3,3 +3,16 @@ export type DirectoryContents = {
directories: Array<string>,
editable: Array<string>
}
export type ServerDatabase = {
id: string,
name: string,
connections_from: string,
username: string,
host: {
address: string,
port: number,
},
password: string,
showPassword: boolean,
}