From b45592466edf7b710dd556f2a56d1c0f97200767 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 6 Jan 2021 16:38:39 -0700 Subject: [PATCH] admin(ui): add missing API requests --- .../scripts/api/admin/databases/createDatabase.ts | 12 ++++++++++++ .../scripts/api/admin/databases/deleteDatabase.ts | 9 +++++++++ resources/scripts/api/admin/databases/getDatabase.ts | 10 ++++++++++ .../scripts/api/admin/locations/createLocation.ts | 4 ++-- .../scripts/api/admin/locations/deleteLocation.ts | 9 +++++++++ resources/scripts/api/admin/locations/getLocation.ts | 10 ++++++++++ resources/scripts/api/admin/mounts/createMount.ts | 12 ++++++++++++ resources/scripts/api/admin/mounts/deleteMount.ts | 9 +++++++++ resources/scripts/api/admin/mounts/getMount.ts | 10 ++++++++++ resources/scripts/api/admin/nests/createNest.ts | 4 ++-- resources/scripts/api/admin/nests/deleteNest.ts | 9 +++++++++ resources/scripts/api/admin/nests/eggs/createEgg.ts | 12 ++++++++++++ resources/scripts/api/admin/nests/eggs/deleteEgg.ts | 9 +++++++++ resources/scripts/api/admin/nests/eggs/getEgg.ts | 10 ++++++++++ resources/scripts/api/admin/nests/eggs/getEggs.ts | 4 ++-- resources/scripts/api/admin/nests/getNest.ts | 10 ++++++++++ resources/scripts/api/admin/nodes/createNode.ts | 12 ++++++++++++ resources/scripts/api/admin/nodes/deleteNode.ts | 9 +++++++++ resources/scripts/api/admin/nodes/getNode.ts | 10 ++++++++++ resources/scripts/api/admin/roles/createRole.ts | 4 ++-- resources/scripts/api/admin/roles/deleteRole.ts | 9 +++++++++ resources/scripts/api/admin/roles/getRole.ts | 10 ++++++++++ resources/scripts/api/admin/servers/createServer.ts | 12 ++++++++++++ resources/scripts/api/admin/servers/deleteServer.ts | 9 +++++++++ resources/scripts/api/admin/servers/getServer.ts | 10 ++++++++++ resources/scripts/api/admin/servers/getServers.ts | 4 ++-- resources/scripts/api/admin/users/createUser.ts | 12 ++++++++++++ resources/scripts/api/admin/users/deleteUser.ts | 9 +++++++++ resources/scripts/api/admin/users/getUser.ts | 10 ++++++++++ 29 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 resources/scripts/api/admin/databases/createDatabase.ts create mode 100644 resources/scripts/api/admin/databases/deleteDatabase.ts create mode 100644 resources/scripts/api/admin/databases/getDatabase.ts create mode 100644 resources/scripts/api/admin/locations/deleteLocation.ts create mode 100644 resources/scripts/api/admin/locations/getLocation.ts create mode 100644 resources/scripts/api/admin/mounts/createMount.ts create mode 100644 resources/scripts/api/admin/mounts/deleteMount.ts create mode 100644 resources/scripts/api/admin/mounts/getMount.ts create mode 100644 resources/scripts/api/admin/nests/deleteNest.ts create mode 100644 resources/scripts/api/admin/nests/eggs/createEgg.ts create mode 100644 resources/scripts/api/admin/nests/eggs/deleteEgg.ts create mode 100644 resources/scripts/api/admin/nests/eggs/getEgg.ts create mode 100644 resources/scripts/api/admin/nests/getNest.ts create mode 100644 resources/scripts/api/admin/nodes/createNode.ts create mode 100644 resources/scripts/api/admin/nodes/deleteNode.ts create mode 100644 resources/scripts/api/admin/nodes/getNode.ts create mode 100644 resources/scripts/api/admin/roles/deleteRole.ts create mode 100644 resources/scripts/api/admin/roles/getRole.ts create mode 100644 resources/scripts/api/admin/servers/createServer.ts create mode 100644 resources/scripts/api/admin/servers/deleteServer.ts create mode 100644 resources/scripts/api/admin/servers/getServer.ts create mode 100644 resources/scripts/api/admin/users/createUser.ts create mode 100644 resources/scripts/api/admin/users/deleteUser.ts create mode 100644 resources/scripts/api/admin/users/getUser.ts diff --git a/resources/scripts/api/admin/databases/createDatabase.ts b/resources/scripts/api/admin/databases/createDatabase.ts new file mode 100644 index 000000000..70bb33fd5 --- /dev/null +++ b/resources/scripts/api/admin/databases/createDatabase.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; + +export default (name: string): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/databases', { + name, + }) + .then(({ data }) => resolve(rawDataToDatabase(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/databases/deleteDatabase.ts b/resources/scripts/api/admin/databases/deleteDatabase.ts new file mode 100644 index 000000000..436aeaa85 --- /dev/null +++ b/resources/scripts/api/admin/databases/deleteDatabase.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/databases/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/databases/getDatabase.ts b/resources/scripts/api/admin/databases/getDatabase.ts new file mode 100644 index 000000000..b10d17877 --- /dev/null +++ b/resources/scripts/api/admin/databases/getDatabase.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/databases/${id}`) + .then(({ data }) => resolve(rawDataToDatabase(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/locations/createLocation.ts b/resources/scripts/api/admin/locations/createLocation.ts index 26e66d02c..5093141cb 100644 --- a/resources/scripts/api/admin/locations/createLocation.ts +++ b/resources/scripts/api/admin/locations/createLocation.ts @@ -1,12 +1,12 @@ import http from '@/api/http'; -import { Location } from '@/api/admin/locations/getLocations'; +import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; export default (short: string, long?: string): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/locations', { short, long, }) - .then(({ data }) => resolve(data.attributes)) + .then(({ data }) => resolve(rawDataToLocation(data))) .catch(reject); }); }; diff --git a/resources/scripts/api/admin/locations/deleteLocation.ts b/resources/scripts/api/admin/locations/deleteLocation.ts new file mode 100644 index 000000000..85b42d60e --- /dev/null +++ b/resources/scripts/api/admin/locations/deleteLocation.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/locations/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/locations/getLocation.ts b/resources/scripts/api/admin/locations/getLocation.ts new file mode 100644 index 000000000..8831fdba3 --- /dev/null +++ b/resources/scripts/api/admin/locations/getLocation.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/locations/${id}`) + .then(({ data }) => resolve(rawDataToLocation(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/mounts/createMount.ts b/resources/scripts/api/admin/mounts/createMount.ts new file mode 100644 index 000000000..536677ef8 --- /dev/null +++ b/resources/scripts/api/admin/mounts/createMount.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; + +export default (name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/mounts', { + name, description, source, target, read_only: readOnly, user_mountable: userMountable, + }) + .then(({ data }) => resolve(rawDataToMount(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/mounts/deleteMount.ts b/resources/scripts/api/admin/mounts/deleteMount.ts new file mode 100644 index 000000000..e4ec1d113 --- /dev/null +++ b/resources/scripts/api/admin/mounts/deleteMount.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/mounts/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/mounts/getMount.ts b/resources/scripts/api/admin/mounts/getMount.ts new file mode 100644 index 000000000..7f727e88f --- /dev/null +++ b/resources/scripts/api/admin/mounts/getMount.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/mounts/${id}`) + .then(({ data }) => resolve(rawDataToMount(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/createNest.ts b/resources/scripts/api/admin/nests/createNest.ts index 49004a88d..ace17df68 100644 --- a/resources/scripts/api/admin/nests/createNest.ts +++ b/resources/scripts/api/admin/nests/createNest.ts @@ -1,12 +1,12 @@ import http from '@/api/http'; -import { Nest } from '@/api/admin/nests/getNests'; +import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; export default (name: string, description?: string): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/nests', { name, description, }) - .then(({ data }) => resolve(data.attributes)) + .then(({ data }) => resolve(rawDataToNest(data))) .catch(reject); }); }; diff --git a/resources/scripts/api/admin/nests/deleteNest.ts b/resources/scripts/api/admin/nests/deleteNest.ts new file mode 100644 index 000000000..d6d4ae3a5 --- /dev/null +++ b/resources/scripts/api/admin/nests/deleteNest.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/nests/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/eggs/createEgg.ts b/resources/scripts/api/admin/nests/eggs/createEgg.ts new file mode 100644 index 000000000..8843a19ea --- /dev/null +++ b/resources/scripts/api/admin/nests/eggs/createEgg.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { Egg, rawDataToEgg } from '@/api/admin/nests/eggs/getEggs'; + +export default (nestId: number, name: string): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/eggs', { + nestId, name, + }) + .then(({ data }) => resolve(rawDataToEgg(data.attributes))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/eggs/deleteEgg.ts b/resources/scripts/api/admin/nests/eggs/deleteEgg.ts new file mode 100644 index 000000000..635f3d6c2 --- /dev/null +++ b/resources/scripts/api/admin/nests/eggs/deleteEgg.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/eggs/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/eggs/getEgg.ts b/resources/scripts/api/admin/nests/eggs/getEgg.ts new file mode 100644 index 000000000..4afc630c3 --- /dev/null +++ b/resources/scripts/api/admin/nests/eggs/getEgg.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Egg, rawDataToEgg } from '@/api/admin/nests/eggs/getEggs'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/eggs/${id}`) + .then(({ data }) => resolve(rawDataToEgg(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/eggs/getEggs.ts b/resources/scripts/api/admin/nests/eggs/getEggs.ts index 5edd7b19f..3ef36a52b 100644 --- a/resources/scripts/api/admin/nests/eggs/getEggs.ts +++ b/resources/scripts/api/admin/nests/eggs/getEggs.ts @@ -48,9 +48,9 @@ export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({ updatedAt: new Date(attributes.updated_at), }); -export default (id: number): Promise => { +export default (nestId: number): Promise => { return new Promise((resolve, reject) => { - http.get(`/api/application/nests/${id}`) + http.get(`/api/application/nests/${nestId}`) .then(({ data }) => resolve((data.data || []).map(rawDataToEgg))) .catch(reject); }); diff --git a/resources/scripts/api/admin/nests/getNest.ts b/resources/scripts/api/admin/nests/getNest.ts new file mode 100644 index 000000000..2867fc888 --- /dev/null +++ b/resources/scripts/api/admin/nests/getNest.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/nests/${id}`) + .then(({ data }) => resolve(rawDataToNest(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nodes/createNode.ts b/resources/scripts/api/admin/nodes/createNode.ts new file mode 100644 index 000000000..a05b1cc0f --- /dev/null +++ b/resources/scripts/api/admin/nodes/createNode.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; + +export default (name: string, description?: string): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/nodes', { + name, description, + }) + .then(({ data }) => resolve(rawDataToNode(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nodes/deleteNode.ts b/resources/scripts/api/admin/nodes/deleteNode.ts new file mode 100644 index 000000000..56a426111 --- /dev/null +++ b/resources/scripts/api/admin/nodes/deleteNode.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/nodes/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nodes/getNode.ts b/resources/scripts/api/admin/nodes/getNode.ts new file mode 100644 index 000000000..bdba0f719 --- /dev/null +++ b/resources/scripts/api/admin/nodes/getNode.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/nodes/${id}`) + .then(({ data }) => resolve(rawDataToNode(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/roles/createRole.ts b/resources/scripts/api/admin/roles/createRole.ts index 366589a65..50ee88612 100644 --- a/resources/scripts/api/admin/roles/createRole.ts +++ b/resources/scripts/api/admin/roles/createRole.ts @@ -1,12 +1,12 @@ import http from '@/api/http'; -import { Role } from '@/api/admin/roles/getRoles'; +import { Role, rawDataToRole } from '@/api/admin/roles/getRoles'; export default (name: string, description?: string): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/roles', { name, description, }) - .then(({ data }) => resolve(data.attributes)) + .then(({ data }) => resolve(rawDataToRole(data))) .catch(reject); }); }; diff --git a/resources/scripts/api/admin/roles/deleteRole.ts b/resources/scripts/api/admin/roles/deleteRole.ts new file mode 100644 index 000000000..3452791e1 --- /dev/null +++ b/resources/scripts/api/admin/roles/deleteRole.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/roles/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/roles/getRole.ts b/resources/scripts/api/admin/roles/getRole.ts new file mode 100644 index 000000000..665104869 --- /dev/null +++ b/resources/scripts/api/admin/roles/getRole.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Role, rawDataToRole } from '@/api/admin/roles/getRoles'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/roles/${id}`) + .then(({ data }) => resolve(rawDataToRole(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/servers/createServer.ts b/resources/scripts/api/admin/servers/createServer.ts new file mode 100644 index 000000000..39aa68481 --- /dev/null +++ b/resources/scripts/api/admin/servers/createServer.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; + +export default (name: string, description: string): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/servers', { + name, description, + }) + .then(({ data }) => resolve(rawDataToServer(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/servers/deleteServer.ts b/resources/scripts/api/admin/servers/deleteServer.ts new file mode 100644 index 000000000..579559518 --- /dev/null +++ b/resources/scripts/api/admin/servers/deleteServer.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/servers/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/servers/getServer.ts b/resources/scripts/api/admin/servers/getServer.ts new file mode 100644 index 000000000..4e6b0b5c8 --- /dev/null +++ b/resources/scripts/api/admin/servers/getServer.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/servers/${id}`) + .then(({ data }) => resolve(rawDataToServer(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/servers/getServers.ts b/resources/scripts/api/admin/servers/getServers.ts index 15799985a..c5e919ab1 100644 --- a/resources/scripts/api/admin/servers/getServers.ts +++ b/resources/scripts/api/admin/servers/getServers.ts @@ -23,7 +23,7 @@ export interface Server { }; } -const rawDataToServerObject = ({ attributes }: FractalResponseData): Server => ({ +export const rawDataToServer = ({ attributes }: FractalResponseData): Server => ({ id: attributes.id, externalId: attributes.external_id, uuid: attributes.uuid, @@ -56,7 +56,7 @@ export default (include: string[] = []) => { const { data } = await http.get('/api/application/servers', { params: { include: include.join(','), page } }); return ({ - items: (data.data || []).map(rawDataToServerObject), + items: (data.data || []).map(rawDataToServer), pagination: getPaginationSet(data.meta.pagination), }); }); diff --git a/resources/scripts/api/admin/users/createUser.ts b/resources/scripts/api/admin/users/createUser.ts new file mode 100644 index 000000000..c919e84bd --- /dev/null +++ b/resources/scripts/api/admin/users/createUser.ts @@ -0,0 +1,12 @@ +import http from '@/api/http'; +import { User, rawDataToUser } from '@/api/admin/users/getUsers'; + +export default (name: string): Promise => { + return new Promise((resolve, reject) => { + http.post('/api/application/users', { + name, + }) + .then(({ data }) => resolve(rawDataToUser(data))) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/users/deleteUser.ts b/resources/scripts/api/admin/users/deleteUser.ts new file mode 100644 index 000000000..df5b2e545 --- /dev/null +++ b/resources/scripts/api/admin/users/deleteUser.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.delete(`/api/application/users/${id}`) + .then(() => resolve()) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/users/getUser.ts b/resources/scripts/api/admin/users/getUser.ts new file mode 100644 index 000000000..939f311d8 --- /dev/null +++ b/resources/scripts/api/admin/users/getUser.ts @@ -0,0 +1,10 @@ +import http from '@/api/http'; +import { User, rawDataToUser } from '@/api/admin/users/getUsers'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/users/${id}`) + .then(({ data }) => resolve(rawDataToUser(data))) + .catch(reject); + }); +};