Refactor some endpoints
This commit is contained in:
parent
a0db0bd93c
commit
5f1bee26cf
5 changed files with 11 additions and 10 deletions
|
|
@ -44,7 +44,7 @@ const BottomHeader = () => {
|
||||||
|
|
||||||
function deleteTeam(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
function deleteTeam(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
||||||
if (appState.party.editable && appState.party.id) {
|
if (appState.party.editable && appState.party.id) {
|
||||||
api.endpoints.parties.destroy(appState.party.id, headers)
|
api.endpoints.parties.destroy({ id: appState.party.id, params: headers })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Push to route
|
// Push to route
|
||||||
router.push('/')
|
router.push('/')
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ const CharacterGrid = (props: Props) => {
|
||||||
|
|
||||||
// Methods: Fetching an object from the server
|
// Methods: Fetching an object from the server
|
||||||
async function fetchGrid(shortcode: string) {
|
async function fetchGrid(shortcode: string) {
|
||||||
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'characters' })
|
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'characters', params: headers })
|
||||||
.then(response => processResult(response))
|
.then(response => processResult(response))
|
||||||
.catch(error => processError(error))
|
.catch(error => processError(error))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ const SummonGrid = (props: Props) => {
|
||||||
|
|
||||||
// Methods: Fetching an object from the server
|
// Methods: Fetching an object from the server
|
||||||
async function fetchGrid(shortcode: string) {
|
async function fetchGrid(shortcode: string) {
|
||||||
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'summons' })
|
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'summons', params: headers })
|
||||||
.then(response => processResult(response))
|
.then(response => processResult(response))
|
||||||
.catch(error => processError(error))
|
.catch(error => processError(error))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ const WeaponGrid = (props: Props) => {
|
||||||
|
|
||||||
// Methods: Fetching an object from the server
|
// Methods: Fetching an object from the server
|
||||||
async function fetchGrid(shortcode: string) {
|
async function fetchGrid(shortcode: string) {
|
||||||
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'weapons' })
|
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'weapons', params: headers })
|
||||||
.then(response => processResult(response))
|
.then(response => processResult(response))
|
||||||
.catch(error => processError(error))
|
.catch(error => processError(error))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from "axios"
|
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from "axios"
|
||||||
|
import { appState } from "./appState"
|
||||||
|
|
||||||
interface Entity {
|
interface Entity {
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CollectionEndpoint = (params?: {}) => Promise<AxiosResponse<any>>
|
type CollectionEndpoint = (params?: {}) => Promise<AxiosResponse<any>>
|
||||||
type IdEndpoint = ({ id }: { id: string }) => Promise<AxiosResponse<any>>
|
type IdEndpoint = ({ id, params }: { id: string, params?: {} }) => Promise<AxiosResponse<any>>
|
||||||
type IdWithObjectEndpoint = ({ id, object }: { id: string, object: string }) => Promise<AxiosResponse<any>>
|
type IdWithObjectEndpoint = ({ id, object, params }: { id: string, object: string, params?: {} }) => Promise<AxiosResponse<any>>
|
||||||
type PostEndpoint = (object: {}, headers?: {}) => Promise<AxiosResponse<any>>
|
type PostEndpoint = (object: {}, headers?: {}) => Promise<AxiosResponse<any>>
|
||||||
type PutEndpoint = (id: string, object: {}, headers?: {}) => Promise<AxiosResponse<any>>
|
type PutEndpoint = (id: string, object: {}, headers?: {}) => Promise<AxiosResponse<any>>
|
||||||
type DestroyEndpoint = (id: string, headers?: {}) => Promise<AxiosResponse<any>>
|
type DestroyEndpoint = ({ id, params }: { id: string, params?: {} }) => Promise<AxiosResponse<any>>
|
||||||
|
|
||||||
interface EndpointMap {
|
interface EndpointMap {
|
||||||
getAll: CollectionEndpoint
|
getAll: CollectionEndpoint
|
||||||
|
|
@ -42,11 +43,11 @@ class Api {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getAll: (params?: {}) => axios.get(resourceUrl, params),
|
getAll: (params?: {}) => axios.get(resourceUrl, params),
|
||||||
getOne: ({ id }: { id: string }) => axios.get(`${resourceUrl}/${id}/`),
|
getOne: ({ id, params }: { id: string, params?: {} }) => axios.get(`${resourceUrl}/${id}/`, params),
|
||||||
getOneWithObject: ({ id, object }: { id: string, object: string }) => axios.get(`${resourceUrl}/${id}/${object}`),
|
getOneWithObject: ({ id, object, params }: { id: string, object: string, params?: {} }) => axios.get(`${resourceUrl}/${id}/${object}`, params),
|
||||||
create: (object: {}, headers?: {}) => axios.post(resourceUrl, object, headers),
|
create: (object: {}, headers?: {}) => axios.post(resourceUrl, object, headers),
|
||||||
update: (id: string, object: {}, headers?: {}) => axios.put(`${resourceUrl}/${id}`, object, headers),
|
update: (id: string, object: {}, headers?: {}) => axios.put(`${resourceUrl}/${id}`, object, headers),
|
||||||
destroy: (id: string, headers?: {}) => axios.delete(`${resourceUrl}/${id}`, headers)
|
destroy: ({ id, params }: { id: string, params?: {} }) => axios.delete(`${resourceUrl}/${id}`, params)
|
||||||
} as EndpointMap
|
} as EndpointMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue