admin(ui-api): add 'include' parameter to all requests

This commit is contained in:
Matthew Penner 2021-01-15 09:41:15 -07:00
parent e123367f40
commit 9532ecf867
24 changed files with 48 additions and 48 deletions

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
export default (name: string, host: string, port: number, username: string, password: string): Promise<Database> => {
export default (name: string, host: string, port: number, username: string, password: string, include: string[] = []): Promise<Database> => {
return new Promise((resolve, reject) => {
http.post('/api/application/databases', {
name, host, port, username, password,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToDatabase(data)))
.catch(reject);
});

View File

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

View File

@ -35,11 +35,11 @@ interface ctx {
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
export default () => {
export default (include: string[] = []) => {
const { page } = useContext(Context);
return useSWR<PaginatedResult<Database>>([ 'databases', page ], async () => {
const { data } = await http.get('/api/application/databases', { params: { page } });
const { data } = await http.get('/api/application/databases', { params: { include: include.join(','), page } });
return ({
items: (data.data || []).map(rawDataToDatabase),

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
export default (id: number, name: string, host: string, port: number, username: string, password?: string | undefined): Promise<Database> => {
export default (id: number, name: string, host: string, port: number, username: string, password: string | undefined, include: string[] = []): Promise<Database> => {
return new Promise((resolve, reject) => {
http.patch(`/api/application/databases/${id}`, {
name, host, port, username, password,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToDatabase(data)))
.catch(reject);
});

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations';
export default (short: string, long?: string): Promise<Location> => {
export default (short: string, long: string | null, include: string[] = []): Promise<Location> => {
return new Promise((resolve, reject) => {
http.post('/api/application/locations', {
short, long,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToLocation(data)))
.catch(reject);
});

View File

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

View File

@ -25,11 +25,11 @@ interface ctx {
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
export default () => {
export default (include: string[] = []) => {
const { page } = useContext(Context);
return useSWR<PaginatedResult<Location>>([ 'locations', page ], async () => {
const { data } = await http.get('/api/application/locations', { params: { page } });
const { data } = await http.get('/api/application/locations', { params: { include: include.join(','), page } });
return ({
items: (data.data || []).map(rawDataToLocation),

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations';
export default (id: number, short: string, long?: string): Promise<Location> => {
export default (id: number, short: string, long: string | null, include: string[] = []): Promise<Location> => {
return new Promise((resolve, reject) => {
http.patch(`/api/application/locations/${id}`, {
short, long,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToLocation(data)))
.catch(reject);
});

View File

@ -1,11 +1,11 @@
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> => {
export default (name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise<Mount> => {
return new Promise((resolve, reject) => {
http.post('/api/application/mounts', {
name, description, source, target, read_only: readOnly, user_mountable: userMountable,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToMount(data)))
.catch(reject);
});

View File

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

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts';
export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean): Promise<Mount> => {
export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise<Mount> => {
return new Promise((resolve, reject) => {
http.patch(`/api/application/mounts/${id}`, {
name, description, source, target, read_only: readOnly, user_mountable: userMountable,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToMount(data)))
.catch(reject);
});

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
export default (name: string, description?: string): Promise<Nest> => {
export default (name: string, description: string | null, include: string[] = []): Promise<Nest> => {
return new Promise((resolve, reject) => {
http.post('/api/application/nests', {
name, description,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToNest(data)))
.catch(reject);
});

View File

@ -38,11 +38,11 @@ interface ctx {
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
export default () => {
export default (include: string[] = []) => {
const { page } = useContext(Context);
return useSWR<PaginatedResult<Nest>>([ 'nests', page ], async () => {
const { data } = await http.get('/api/application/nests', { params: { page } });
const { data } = await http.get('/api/application/nests', { params: { include: include.join(','), page } });
return ({
items: (data.data || []).map(rawDataToNest),

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
export default (id: number, name: string, description?: string): Promise<Nest> => {
export default (id: number, name: string, description: string | null, include: string[] = []): Promise<Nest> => {
return new Promise((resolve, reject) => {
http.patch(`/api/application/nests/${id}`, {
name, description,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToNest(data)))
.catch(reject);
});

View File

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

View File

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

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Role, rawDataToRole } from '@/api/admin/roles/getRoles';
export default (name: string, description?: string): Promise<Role> => {
export default (name: string, description: string | null, include: string[] = []): Promise<Role> => {
return new Promise((resolve, reject) => {
http.post('/api/application/roles', {
name, description,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToRole(data)))
.catch(reject);
});

View File

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

View File

@ -12,9 +12,9 @@ export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({
description: attributes.description,
});
export default (): Promise<Role[]> => {
export default (include: string[] = []): Promise<Role[]> => {
return new Promise((resolve, reject) => {
http.get('/api/application/roles')
http.get('/api/application/roles', { params: { include: include.join(',') } })
.then(({ data }) => resolve((data.data || []).map(rawDataToRole)))
.catch(reject);
});

View File

@ -1,11 +1,11 @@
import http from '@/api/http';
import { Role, rawDataToRole } from '@/api/admin/roles/getRoles';
export default (id: number, name: string, description?: string): Promise<Role> => {
export default (id: number, name: string, description: string | null, include: string[] = []): Promise<Role> => {
return new Promise((resolve, reject) => {
http.patch(`/api/application/roles/${id}`, {
name, description,
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToRole(data)))
.catch(reject);
});

View File

@ -34,7 +34,7 @@ interface CreateServerRequest {
};
}
export default (r: CreateServerRequest): Promise<Server> => {
export default (r: CreateServerRequest, include: string[] = []): Promise<Server> => {
return new Promise((resolve, reject) => {
http.post('/api/application/servers', {
name: r.name,
@ -67,7 +67,7 @@ export default (r: CreateServerRequest): Promise<Server> => {
backups: r.featureLimits.backups,
databases: r.featureLimits.databases,
},
})
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToServer(data)))
.catch(reject);
});

View File

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

View File

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

View File

@ -43,11 +43,11 @@ interface ctx {
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
export default () => {
export default (include: string[] = []) => {
const { page } = useContext(Context);
return useSWR<PaginatedResult<User>>([ 'users', page ], async () => {
const { data } = await http.get('/api/application/users', { params: { page } });
const { data } = await http.get('/api/application/users', { params: { include: include.join(','), page } });
return ({
items: (data.data || []).map(rawDataToUser),