From 87442799796343bf4d971d37b09af5ac19b81f25 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 3 Feb 2022 23:50:38 -0800 Subject: [PATCH] Added a new Endpoint type for specific objects in a party --- utils/api.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/api.tsx b/utils/api.tsx index f1ae1b4e..89203821 100644 --- a/utils/api.tsx +++ b/utils/api.tsx @@ -1,4 +1,4 @@ -import axios, { AxiosRequestConfig, AxiosResponse } from "axios" +import axios, { Axios, AxiosRequestConfig, AxiosResponse } from "axios" interface Entity { name: string @@ -6,11 +6,13 @@ interface Entity { type CollectionEndpoint = ({ query }: { query: AxiosRequestConfig }) => Promise> type IdEndpoint = ({ id }: { id: string }) => Promise> +type IdWithObjectEndpoint = ({ id, object }: { id: string, object: string }) => Promise> type PostEndpoint = (object: {}, headers?: {}) => Promise> interface EndpointMap { getAll: CollectionEndpoint getOne: IdEndpoint + getOneWithObject: IdWithObjectEndpoint create: PostEndpoint update: PostEndpoint destroy: IdEndpoint @@ -38,7 +40,8 @@ class Api { return { getAll: ({ query }: { query: AxiosRequestConfig }) => axios.get(resourceUrl, { params: { query }}), - getOne: ({ id }: { id: string }) => axios.get(`${resourceUrl}/${id}`), + getOne: ({ id }: { id: string }) => axios.get(`${resourceUrl}/${id}/`), + getOneWithObject: ({ id, object }: { id: string, object: string }) => axios.get(`${resourceUrl}/${id}/${object}`), create: (object: {}, headers?: {}) => axios.post(resourceUrl, object, headers), update: (object: {}, headers?: {}) => axios.put(resourceUrl, object, headers), destroy: ({ id }: { id: string }) => axios.delete(`${resourceUrl}/${id}`)