UNPKG

commerce-vuex

Version:
61 lines (52 loc) 2.28 kB
import { auth, nav } from 'oak-vuex' const { getHubAuthHeader } = auth const { wrapRequest, wrapRequestWithRange } = nav const hubName = process.env.VUE_APP_RETAINHUB_NAME const oakTradeApiUrl = process.env.VUE_APP_RETAINHUB_COMMERCE_API_URL const doFetchList = wrapRequestWithRange(( {amountLike,businessEntityId, serviceId, appId, limit, offset }) => { const requestOptions = { method: 'GET', headers: { 'Content-type': 'application/json', 'Prefer': 'count=exact', ...getHubAuthHeader(hubName) } } const params = { app_id:`eq.${appId}`, business_entity_id:`eq.${businessEntityId}`, service_id:`eq.${serviceId}`,limit: limit || 50, offset: offset || 0 } if (amountLike) params['amount'] = `eq.${amountLike}` const qs = Object.keys(params).map(key => key + '=' + params[key]).join('&'); return fetch(`${oakTradeApiUrl}/service_pricing?${qs}&select=*,business_entity!business_entity_id(name)`, requestOptions); }) const doPostOne = wrapRequest((pricing) => { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', 'Prefer': 'return=representation', ...getHubAuthHeader(hubName) }, body: JSON.stringify(pricing) } return fetch(`${oakTradeApiUrl}/service_pricing`, requestOptions) }) const doPatchOne = wrapRequest((pricing) => { const requestOptions = { method: 'PATCH', headers: { 'Content-Type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', 'Prefer': 'return=representation', ...getHubAuthHeader(hubName) }, body: JSON.stringify(pricing) } return fetch(`${oakTradeApiUrl}/service_pricing?id=eq.${pricing.id}`, requestOptions) }) const doFetchOne = wrapRequest(({ servicePricingId,appId }) => { const requestOptions = { method: 'GET', headers: { 'Content-type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', ...getHubAuthHeader(hubName) } } return fetch(`${oakTradeApiUrl}/service_pricing?id=eq.${servicePricingId}&app_id=eq.${appId}`, requestOptions) }) export default { doFetchOne, doFetchList, doPostOne, doPatchOne }