mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import axios from 'axios';
|
|
import CONFIG from '../config'
|
|
|
|
const apiGet = async (url) => {
|
|
try {
|
|
const result = await axios.get(url);
|
|
if(result.status !== 200){
|
|
throw new Error('HTTP Status Error '+result.status)
|
|
}
|
|
if(result.data.state !== 'success'){
|
|
throw new Error(result.data.msg)
|
|
}
|
|
return { success: true, result }
|
|
} catch(error){
|
|
return { success: false, result: error}
|
|
}
|
|
}
|
|
|
|
const apiPost = async (url, payload) => {
|
|
try {
|
|
const result = await axios.post(url, payload);
|
|
if(result.status !== 200){
|
|
throw new Error('HTTP Status Error '+result.status)
|
|
}
|
|
if(result.data.state !== 'success'){
|
|
throw new Error(result.data.msg)
|
|
}
|
|
return { success: true, result }
|
|
} catch(error){
|
|
return { success: false, result: error}
|
|
}
|
|
}
|
|
|
|
const communityAPI = {
|
|
balance: async (session_id) => {
|
|
return apiGet(CONFIG.COMMUNITY_API_STATE_BALANCE_URL + 'ajaxGetBalance/' + session_id)
|
|
},
|
|
transactions: async (session_id) => {
|
|
return apiGet(CONFIG.COMMUNITY_API_STATE_BALANCE_URL + 'ajaxListTransactions/' + session_id)
|
|
},
|
|
create: async (session_id, email, amount, memo, target_date = new Date() ) => {
|
|
const payload = {
|
|
session_id,
|
|
email,
|
|
amount,
|
|
target_date,
|
|
memo,
|
|
auto_sign: true
|
|
}
|
|
return apiPost(CONFIG.COMMUNITY_API_TRANSACTION_CREATION_URL + 'ajaxCreate/', payload)
|
|
}
|
|
}
|
|
|
|
export default communityAPI |