From 9532ecf867da93a589dc23ac4f7819e0fa662779 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 15 Jan 2021 09:41:15 -0700 Subject: [PATCH] admin(ui-api): add 'include' parameter to all requests --- resources/scripts/api/admin/databases/createDatabase.ts | 4 ++-- resources/scripts/api/admin/databases/getDatabase.ts | 4 ++-- resources/scripts/api/admin/databases/getDatabases.ts | 4 ++-- resources/scripts/api/admin/databases/updateDatabase.ts | 4 ++-- resources/scripts/api/admin/locations/createLocation.ts | 4 ++-- resources/scripts/api/admin/locations/getLocation.ts | 4 ++-- resources/scripts/api/admin/locations/getLocations.ts | 4 ++-- resources/scripts/api/admin/locations/updateLocation.ts | 4 ++-- resources/scripts/api/admin/mounts/createMount.ts | 4 ++-- resources/scripts/api/admin/mounts/getMount.ts | 4 ++-- resources/scripts/api/admin/mounts/updateMount.ts | 4 ++-- resources/scripts/api/admin/nests/createNest.ts | 4 ++-- resources/scripts/api/admin/nests/getNests.ts | 4 ++-- resources/scripts/api/admin/nests/updateNest.ts | 4 ++-- resources/scripts/api/admin/nodes/createNode.ts | 4 ++-- resources/scripts/api/admin/nodes/getNode.ts | 4 ++-- resources/scripts/api/admin/roles/createRole.ts | 4 ++-- resources/scripts/api/admin/roles/getRole.ts | 4 ++-- resources/scripts/api/admin/roles/getRoles.ts | 4 ++-- resources/scripts/api/admin/roles/updateRole.ts | 4 ++-- resources/scripts/api/admin/servers/createServer.ts | 4 ++-- resources/scripts/api/admin/users/createUser.ts | 4 ++-- resources/scripts/api/admin/users/getUser.ts | 4 ++-- resources/scripts/api/admin/users/getUsers.ts | 4 ++-- 24 files changed, 48 insertions(+), 48 deletions(-) diff --git a/resources/scripts/api/admin/databases/createDatabase.ts b/resources/scripts/api/admin/databases/createDatabase.ts index a2a273c7f..98d37bf1d 100644 --- a/resources/scripts/api/admin/databases/createDatabase.ts +++ b/resources/scripts/api/admin/databases/createDatabase.ts @@ -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 => { +export default (name: string, host: string, port: number, username: string, password: string, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/databases/getDatabase.ts b/resources/scripts/api/admin/databases/getDatabase.ts index b10d17877..0af69fcd6 100644 --- a/resources/scripts/api/admin/databases/getDatabase.ts +++ b/resources/scripts/api/admin/databases/getDatabase.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/databases/getDatabases.ts b/resources/scripts/api/admin/databases/getDatabases.ts index 08ada8d95..750597f8e 100644 --- a/resources/scripts/api/admin/databases/getDatabases.ts +++ b/resources/scripts/api/admin/databases/getDatabases.ts @@ -35,11 +35,11 @@ interface ctx { export const Context = createContext({ page: 1, setPage: () => 1 }); -export default () => { +export default (include: string[] = []) => { const { page } = useContext(Context); return useSWR>([ '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), diff --git a/resources/scripts/api/admin/databases/updateDatabase.ts b/resources/scripts/api/admin/databases/updateDatabase.ts index 5c9cabba1..7d01a9024 100644 --- a/resources/scripts/api/admin/databases/updateDatabase.ts +++ b/resources/scripts/api/admin/databases/updateDatabase.ts @@ -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 => { +export default (id: number, name: string, host: string, port: number, username: string, password: string | undefined, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/locations/createLocation.ts b/resources/scripts/api/admin/locations/createLocation.ts index 5093141cb..053148fc4 100644 --- a/resources/scripts/api/admin/locations/createLocation.ts +++ b/resources/scripts/api/admin/locations/createLocation.ts @@ -1,11 +1,11 @@ import http from '@/api/http'; import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; -export default (short: string, long?: string): Promise => { +export default (short: string, long: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/locations', { short, long, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToLocation(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/locations/getLocation.ts b/resources/scripts/api/admin/locations/getLocation.ts index 8831fdba3..9a1aad4bc 100644 --- a/resources/scripts/api/admin/locations/getLocation.ts +++ b/resources/scripts/api/admin/locations/getLocation.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/locations/getLocations.ts b/resources/scripts/api/admin/locations/getLocations.ts index f165422a2..6c70bab6f 100644 --- a/resources/scripts/api/admin/locations/getLocations.ts +++ b/resources/scripts/api/admin/locations/getLocations.ts @@ -25,11 +25,11 @@ interface ctx { export const Context = createContext({ page: 1, setPage: () => 1 }); -export default () => { +export default (include: string[] = []) => { const { page } = useContext(Context); return useSWR>([ '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), diff --git a/resources/scripts/api/admin/locations/updateLocation.ts b/resources/scripts/api/admin/locations/updateLocation.ts index 2ac5ea346..bbb5f8f4c 100644 --- a/resources/scripts/api/admin/locations/updateLocation.ts +++ b/resources/scripts/api/admin/locations/updateLocation.ts @@ -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 => { +export default (id: number, short: string, long: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.patch(`/api/application/locations/${id}`, { short, long, - }) + }, { params: { include: include.join(',') } }) .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 index 536677ef8..63538c821 100644 --- a/resources/scripts/api/admin/mounts/createMount.ts +++ b/resources/scripts/api/admin/mounts/createMount.ts @@ -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 => { +export default (name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/mounts/getMount.ts b/resources/scripts/api/admin/mounts/getMount.ts index 7f727e88f..9bd8a56e9 100644 --- a/resources/scripts/api/admin/mounts/getMount.ts +++ b/resources/scripts/api/admin/mounts/getMount.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/mounts/updateMount.ts b/resources/scripts/api/admin/mounts/updateMount.ts index f647c7132..c2485777a 100644 --- a/resources/scripts/api/admin/mounts/updateMount.ts +++ b/resources/scripts/api/admin/mounts/updateMount.ts @@ -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 => { +export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/nests/createNest.ts b/resources/scripts/api/admin/nests/createNest.ts index ace17df68..6f8d045fa 100644 --- a/resources/scripts/api/admin/nests/createNest.ts +++ b/resources/scripts/api/admin/nests/createNest.ts @@ -1,11 +1,11 @@ import http from '@/api/http'; import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; -export default (name: string, description?: string): Promise => { +export default (name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/nests', { name, description, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToNest(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/nests/getNests.ts b/resources/scripts/api/admin/nests/getNests.ts index 743698a6e..548ed2dba 100644 --- a/resources/scripts/api/admin/nests/getNests.ts +++ b/resources/scripts/api/admin/nests/getNests.ts @@ -38,11 +38,11 @@ interface ctx { export const Context = createContext({ page: 1, setPage: () => 1 }); -export default () => { +export default (include: string[] = []) => { const { page } = useContext(Context); return useSWR>([ '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), diff --git a/resources/scripts/api/admin/nests/updateNest.ts b/resources/scripts/api/admin/nests/updateNest.ts index 9a87c76d3..869f0532b 100644 --- a/resources/scripts/api/admin/nests/updateNest.ts +++ b/resources/scripts/api/admin/nests/updateNest.ts @@ -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 => { +export default (id: number, name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.patch(`/api/application/nests/${id}`, { name, description, - }) + }, { params: { include: include.join(',') } }) .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 index a05b1cc0f..4d2397e98 100644 --- a/resources/scripts/api/admin/nodes/createNode.ts +++ b/resources/scripts/api/admin/nodes/createNode.ts @@ -1,11 +1,11 @@ import http from '@/api/http'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; -export default (name: string, description?: string): Promise => { +export default (name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/nodes', { name, description, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToNode(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/nodes/getNode.ts b/resources/scripts/api/admin/nodes/getNode.ts index bdba0f719..b940c8e2e 100644 --- a/resources/scripts/api/admin/nodes/getNode.ts +++ b/resources/scripts/api/admin/nodes/getNode.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/roles/createRole.ts b/resources/scripts/api/admin/roles/createRole.ts index 50ee88612..7780499bc 100644 --- a/resources/scripts/api/admin/roles/createRole.ts +++ b/resources/scripts/api/admin/roles/createRole.ts @@ -1,11 +1,11 @@ import http from '@/api/http'; import { Role, rawDataToRole } from '@/api/admin/roles/getRoles'; -export default (name: string, description?: string): Promise => { +export default (name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/roles', { name, description, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToRole(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/roles/getRole.ts b/resources/scripts/api/admin/roles/getRole.ts index 665104869..91403ecfa 100644 --- a/resources/scripts/api/admin/roles/getRole.ts +++ b/resources/scripts/api/admin/roles/getRole.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { Role, rawDataToRole } from '@/api/admin/roles/getRoles'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/roles/getRoles.ts b/resources/scripts/api/admin/roles/getRoles.ts index 479e9efa4..1bc50ae1c 100644 --- a/resources/scripts/api/admin/roles/getRoles.ts +++ b/resources/scripts/api/admin/roles/getRoles.ts @@ -12,9 +12,9 @@ export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({ description: attributes.description, }); -export default (): Promise => { +export default (include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/roles/updateRole.ts b/resources/scripts/api/admin/roles/updateRole.ts index 43558073f..398859062 100644 --- a/resources/scripts/api/admin/roles/updateRole.ts +++ b/resources/scripts/api/admin/roles/updateRole.ts @@ -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 => { +export default (id: number, name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.patch(`/api/application/roles/${id}`, { name, description, - }) + }, { params: { include: include.join(',') } }) .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 index fd64dcbd7..88021de80 100644 --- a/resources/scripts/api/admin/servers/createServer.ts +++ b/resources/scripts/api/admin/servers/createServer.ts @@ -34,7 +34,7 @@ interface CreateServerRequest { }; } -export default (r: CreateServerRequest): Promise => { +export default (r: CreateServerRequest, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/servers', { name: r.name, @@ -67,7 +67,7 @@ export default (r: CreateServerRequest): Promise => { backups: r.featureLimits.backups, databases: r.featureLimits.databases, }, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToServer(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/users/createUser.ts b/resources/scripts/api/admin/users/createUser.ts index c919e84bd..d6ddc51da 100644 --- a/resources/scripts/api/admin/users/createUser.ts +++ b/resources/scripts/api/admin/users/createUser.ts @@ -1,11 +1,11 @@ import http from '@/api/http'; import { User, rawDataToUser } from '@/api/admin/users/getUsers'; -export default (name: string): Promise => { +export default (name: string, include: string[] = []): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/users', { name, - }) + }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToUser(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/users/getUser.ts b/resources/scripts/api/admin/users/getUser.ts index 939f311d8..db954065e 100644 --- a/resources/scripts/api/admin/users/getUser.ts +++ b/resources/scripts/api/admin/users/getUser.ts @@ -1,9 +1,9 @@ import http from '@/api/http'; import { User, rawDataToUser } from '@/api/admin/users/getUsers'; -export default (id: number): Promise => { +export default (id: number, include: string[] = []): Promise => { 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); }); diff --git a/resources/scripts/api/admin/users/getUsers.ts b/resources/scripts/api/admin/users/getUsers.ts index dfa0c9bee..ee70fc647 100644 --- a/resources/scripts/api/admin/users/getUsers.ts +++ b/resources/scripts/api/admin/users/getUsers.ts @@ -43,11 +43,11 @@ interface ctx { export const Context = createContext({ page: 1, setPage: () => 1 }); -export default () => { +export default (include: string[] = []) => { const { page } = useContext(Context); return useSWR>([ '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),