unistore wip

This commit is contained in:
ntr committed 2022-09-03 14:26:41 +10:00
1 parent a43d4f32e4
commit cf01670ee6
17 files changed
+253 -79

No files matched your search

+101
View File
@@ -0,0 +1,101 @@
import axios, { AxiosInstance } from 'axios';
type ApiResponse = [string | null, any | null];
declare module 'axios' {
export interface AxiosInstance {
request(config: AxiosRequestConfig): Promise<ApiResponse>;
get(url: string, config?: AxiosRequestConfig): Promise<ApiResponse>;
delete(url: string, config?: AxiosRequestConfig): Promise<ApiResponse>;
head(url: string, config?: AxiosRequestConfig): Promise<ApiResponse>;
post(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse>;
put(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse>;
patch(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse>;
}
}
const api = axios.create({
baseURL: '/api',
withCredentials: true
});
function onSuccess(response) {
return [null, response.data];
}
function onError(error) {
if (error.response) return [error.response.data.error, null];
if (error.request) return ['Network Error', null];
return ['Unknown Error', null];
}
api.interceptors.response.use(onSuccess, onError);
const actions = {
getBundles: async function getBundles() {
return api.get('/acp/bundles');
},
getOffers: async function getOffers() {
return api.get('/user/offers');
},
getOffersAcp: async function getOffersAcp() {
return api.get('/acp/offers');
},
getWants: async function getWants() {
return api.get('/want/all');
},
postWantSearch: async function postWantSearch(artist, title) {
return api.post('/want/search', { artist, title });
},
postWant: async function postWant(releaseId) {
return api.post('/want', { releaseId });
},
postDiscogs: async function postDiscogs(username) {
return api.post('/want/discogs', { username });
},
getLogin: async function getLogin() {
return api.get('/auth/login')
},
postLogin: async function postLogin(email, password) {
return api.post('/auth/login', {
email,
password,
// discogs,
});
},
postLogout: async function postLogout() {
return api.post('/auth/logout', {});
},
postRegister: async function postRegister(email, password) {
return api.post('/auth/register', {
email,
password,
});
},
postOffers: async function postOffers(listingIds, shipping, baseShipping) {
return api.post('/offers', {
listingIds,
shipping,
baseShipping,
});
},
postOfferAccept: async function postOffers(id) {
return api.post('/offer/accept', {
id,
});
},
};
export default actions;