UNPKG

commerce-vuex

Version:
67 lines (63 loc) 2.66 kB
import { auth, nav } from 'oak-vuex' const { getHubAuthHeader } = auth const { wrapRequest,wrapRequestWithRange } = nav const hubName = process.env.VUE_APP_ASHTA_HUB_NAME const ashtaApiUrl = process.env.VUE_APP_ASHTA_API_URL const doFetchBusinessConnectionLookUp = wrapRequest(({filters}) => { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', ...getHubAuthHeader(hubName) }, body: JSON.stringify({filters:filters}) } return fetch(`${ashtaApiUrl}/rpc/business_connection_lookup`, requestOptions) }) const doFetchList = wrapRequestWithRange(({ nameLike, ownerId, limit,offset,sortByDate}) => { const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/json', 'Prefer': 'count=estimated', ...getHubAuthHeader(hubName) }, }; const params = { limit: limit || 50, offset: offset || 0 } if (nameLike) params['secondary_business_name'] = `ilike.*${nameLike}*` if (ownerId) params['primary_business_id'] = `eq.${ownerId}` if (sortByDate) params['order'] = `created_at.desc` const qs = Object.keys(params).map(key => key + '=' + params[key]).join('&'); return fetch(`${ashtaApiUrl}/business_connection?${qs}`, requestOptions) //&select=*,brand_profile(name) }) const doPostOne = wrapRequest((connection) => { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', 'Prefer': 'return=representation', ...getHubAuthHeader(hubName) }, body: JSON.stringify(connection) }; return fetch(`${ashtaApiUrl}/business_connection`, requestOptions) }) const doFetchOne = wrapRequest(({connectionBusinessEntityId}) => { const requestOptions = { method: 'GET', headers: { 'Content-type': 'application/json', 'Accept': 'application/vnd.pgrst.object+json', ...getHubAuthHeader(hubName) }, }; return fetch(`${ashtaApiUrl}/business_connection?id=eq.${connectionBusinessEntityId}`, requestOptions); }) const doPatchOne = wrapRequest(({updateProperty,connectionId}) => { const requestOptions = { method: 'PATCH', headers: { 'Content-Type': 'application/json', 'Prefer': 'return=representation', ...getHubAuthHeader(hubName) }, body: JSON.stringify(updateProperty) }; return fetch(`${ashtaApiUrl}/business_connection?id=eq.${connectionId}`, requestOptions) }) export default { doFetchList,doFetchOne,doPatchOne,doPostOne,doFetchBusinessConnectionLookUp }