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