Migrate last of the SFC's to TS files
This commit is contained in:
parent
5cb57af193
commit
40aa3da5de
9 changed files with 291 additions and 251 deletions
30
resources/assets/scripts/api/server/createDatabase.ts
Normal file
30
resources/assets/scripts/api/server/createDatabase.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue