admin(ui): add missing API requests

This commit is contained in:
Matthew Penner 2021-01-06 16:38:39 -07:00
parent 63daa7b14f
commit b45592466e
29 changed files with 253 additions and 10 deletions

View File

@ -0,0 +1,12 @@
import http from '@/api/http';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
export default (name: string): Promise<Database> => {
return new Promise((resolve, reject) => {
http.post('/api/application/databases', {
name,
})
.then(({ data }) => resolve(rawDataToDatabase(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/databases/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
export default (id: number): Promise<Database> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/databases/${id}`)
.then(({ data }) => resolve(rawDataToDatabase(data)))
.catch(reject);
});
};

View File

@ -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<Location> => {
return new Promise((resolve, reject) => {
http.post('/api/application/locations', {
short, long,
})
.then(({ data }) => resolve(data.attributes))
.then(({ data }) => resolve(rawDataToLocation(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/locations/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations';
export default (id: number): Promise<Location> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/locations/${id}`)
.then(({ data }) => resolve(rawDataToLocation(data)))
.catch(reject);
});
};

View File

@ -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<Mount> => {
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);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/mounts/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts';
export default (id: number): Promise<Mount> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/mounts/${id}`)
.then(({ data }) => resolve(rawDataToMount(data)))
.catch(reject);
});
};

View File

@ -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<Nest> => {
return new Promise((resolve, reject) => {
http.post('/api/application/nests', {
name, description,
})
.then(({ data }) => resolve(data.attributes))
.then(({ data }) => resolve(rawDataToNest(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/nests/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -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<Egg> => {
return new Promise((resolve, reject) => {
http.post('/api/application/eggs', {
nestId, name,
})
.then(({ data }) => resolve(rawDataToEgg(data.attributes)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/eggs/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Egg, rawDataToEgg } from '@/api/admin/nests/eggs/getEggs';
export default (id: number): Promise<Egg> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/eggs/${id}`)
.then(({ data }) => resolve(rawDataToEgg(data)))
.catch(reject);
});
};

View File

@ -48,9 +48,9 @@ export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({
updatedAt: new Date(attributes.updated_at),
});
export default (id: number): Promise<Egg[]> => {
export default (nestId: number): Promise<Egg[]> => {
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);
});

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
export default (id: number): Promise<Nest> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/nests/${id}`)
.then(({ data }) => resolve(rawDataToNest(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,12 @@
import http from '@/api/http';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
export default (name: string, description?: string): Promise<Node> => {
return new Promise((resolve, reject) => {
http.post('/api/application/nodes', {
name, description,
})
.then(({ data }) => resolve(rawDataToNode(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/nodes/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
export default (id: number): Promise<Node> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/nodes/${id}`)
.then(({ data }) => resolve(rawDataToNode(data)))
.catch(reject);
});
};

View File

@ -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<Role> => {
return new Promise((resolve, reject) => {
http.post('/api/application/roles', {
name, description,
})
.then(({ data }) => resolve(data.attributes))
.then(({ data }) => resolve(rawDataToRole(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/roles/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Role, rawDataToRole } from '@/api/admin/roles/getRoles';
export default (id: number): Promise<Role> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/roles/${id}`)
.then(({ data }) => resolve(rawDataToRole(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,12 @@
import http from '@/api/http';
import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
export default (name: string, description: string): Promise<Server> => {
return new Promise((resolve, reject) => {
http.post('/api/application/servers', {
name, description,
})
.then(({ data }) => resolve(rawDataToServer(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/servers/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
export default (id: number): Promise<Server> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/servers/${id}`)
.then(({ data }) => resolve(rawDataToServer(data)))
.catch(reject);
});
};

View File

@ -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),
});
});

View File

@ -0,0 +1,12 @@
import http from '@/api/http';
import { User, rawDataToUser } from '@/api/admin/users/getUsers';
export default (name: string): Promise<User> => {
return new Promise((resolve, reject) => {
http.post('/api/application/users', {
name,
})
.then(({ data }) => resolve(rawDataToUser(data)))
.catch(reject);
});
};

View File

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/application/users/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View File

@ -0,0 +1,10 @@
import http from '@/api/http';
import { User, rawDataToUser } from '@/api/admin/users/getUsers';
export default (id: number): Promise<User> => {
return new Promise((resolve, reject) => {
http.get(`/api/application/users/${id}`)
.then(({ data }) => resolve(rawDataToUser(data)))
.catch(reject);
});
};