admin(ui-api): add 'include' parameter to all requests
This commit is contained in:
parent
e123367f40
commit
9532ecf867
24 changed files with 48 additions and 48 deletions
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue