procurement-vuex
Version:
Commerce vuex module
97 lines (88 loc) • 3.69 kB
JavaScript
import { auth, nav } from 'oak-vuex'
const { getHubAuthHeader } = auth
const { wrapRequest, wrapRequestWithRange ,wrapEmptyRequest} = nav
const hubName = process.env.VUE_APP_RETAINHUB_NAME
const retainhubCommerceApiUrl = process.env.VUE_APP_RETAINHUB_COMMERCE_API_URL
const retainProcurementApiUrl = process.env.VUE_APP_RETAINHUB_PROCUREMENT_API_URL
/*
const doFetchList = wrapRequestWithRange(({ appId, limit, offset, giverId }) => {
const requestOptions = {
method: 'GET',
headers: { 'Content-type': 'application/json', 'Prefer': 'count=exact', ...getHubAuthHeader(hubName) },
};
const params = { giver_id:`eq.${giverId}`,app_id:`eq.${appId}`, limit: limit || 50, offset: offset || 0}
const qs = Object.keys(params).map(key => key + '=' + params[key]).join('&');
return fetch(`${retainhubCommerceApiUrl}/payment?${qs}&select=*,business_entity!recipient_id(name)`, requestOptions);
})
const doFetchOne = wrapRequest(({paymentId}) => {
const requestOptions = {
method: 'GET',
headers: { 'Content-type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', ...getHubAuthHeader(hubName) },
};
return fetch(`${retainhubCommerceApiUrl}/payment?id=eq.${paymentId}&select=*,business_entity!recipient_id(name)`, requestOptions);
})
const doPostOne = wrapRequest((paymentDetails) => {
if(paymentDetails && paymentDetails.currency_iso_3){
let iso3 = paymentDetails.currency_iso_3;
delete paymentDetails.currency_iso_3;
paymentDetails.currency_iso3 = iso3;
}
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json',
'Prefer': 'return=representation', ...getHubAuthHeader(hubName)
},
body: JSON.stringify(paymentDetails)
};
return fetch(`${retainhubCommerceApiUrl}/payment`, requestOptions)
})
const doPatchOne = wrapRequest((paymentDetails) => {
if(paymentDetails && paymentDetails.currency_iso_3){
let iso3 = paymentDetails.currency_iso_3;
delete paymentDetails.currency_iso_3;
paymentDetails.currency_iso3 = iso3;
}
if(paymentDetails && paymentDetails.business_entity){
delete paymentDetails.business_entity;
}
const requestOptions = {
method: 'PATCH',
headers: {
'Content-Type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json',
'Prefer': 'return=representation', ...getHubAuthHeader(hubName)
},
body: JSON.stringify(paymentDetails)
};
return fetch(`${retainhubCommerceApiUrl}/payment?id=eq.${paymentDetails.id}`, requestOptions)
})
const doDeleteSelected = wrapEmptyRequest(({paymentProofId}) => {
const requestOptions = {
method: 'DELETE',
headers: {
'Content-Type': 'application/json', ...getHubAuthHeader(hubName)
},
};
return fetch(`${retainhubCommerceApiUrl}/payment?id=in.(${paymentProofId})`, requestOptions)
})*/
const doOrdersProcessLookupList = wrapRequest(({filter}) => {
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Prefer': 'return=representation', ...getHubAuthHeader(hubName)
},
body: JSON.stringify(
{
filter : filter,
}
)
};
console.log(requestOptions)
// return fetch(`${retainProcurementApiUrl}/rpc/payment_lookup`, requestOptions)
})
export default {
// doFetchOne, doFetchList,
// doPostOne, doPatchOne, doDeleteSelected,
doOrdersProcessLookupList
}