Last active
April 8, 2021 16:49
-
-
Save MosesEsan/7c9e68e2f1ce0be45399a192b016d178 to your computer and use it in GitHub Desktop.
Trade Journal App Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
//API End Point | |
export const TRADE = `/api/trade`; | |
//INDEX | |
export async function getTrades(){ | |
try{ | |
let res = await axios.get(`${TRADE}`); | |
return res.data; | |
}catch (e) { | |
throw handler(e) | |
} | |
} | |
//CREATE AND EDIT | |
export async function createUpdateTrade(data, id){ | |
try{ | |
const options = { | |
method: !id ? 'POST' : 'PUT', | |
headers: {Accept: "application/json",}, | |
data: data, | |
url : id ? `${TRADE}/${id}` : `${TRADE}` | |
}; | |
let res = await axios(options); | |
return res.data; | |
}catch (err) { | |
throw err; | |
} | |
} | |
//READ | |
export async function getTrade(id){ | |
try{ | |
let res = await axios.get(`${TRADE}/${id}`); | |
return res.data; | |
}catch (err) { | |
throw err; | |
} | |
} | |
//DELETE | |
export async function deleteTrade(id) { | |
try { | |
let res = await axios.delete(`${TRADE}/${id}`); | |
return res.data; | |
}catch (err) { | |
throw err; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment