UNPKG

@cgignite/ignite-sf-commerce

Version:

Salesforce Commerce connector for Ignite

45 lines (43 loc) 1.6 kB
const { getAsync, postAsync, putAsync, patchAsync, deleteAsync } = require('./callApi'); const { GetQueryParamString } = require('./functions'); exports.getCatalogsData = async (info) => { try { QueryParamString = GetQueryParamString(info.reqParams); QueryParamString === '' ? ApiURL = info.ApiURL : ApiURL = info.ApiURL + '?' + QueryParamString; if (ApiURL.includes("{shortCode}")) { ApiURL = ApiURL.replace("{shortCode}", info.shortCode); } if (ApiURL.includes("{organizationId}")) { ApiURL = ApiURL.replace("{organizationId}", info.organizationId); } if (ApiURL.includes("{version}")) { ApiURL = ApiURL.replace("{version}", info.version); } if (ApiURL.includes("{catalogId}")) { ApiURL = ApiURL.replace("{catalogId}", info.catalogId); } if (ApiURL.includes("{categoryId}")) { ApiURL = ApiURL.replace("{categoryId}", info.categoryId); } if (ApiURL.includes("{productId}")) { ApiURL = ApiURL.replace("{productId}", info.productId); } if (info.method === 'GET') { return await getAsync(ApiURL, info.reqHeaders) } else if (info.method === 'POST') { return await postAsync(ApiURL, info.reqHeaders, info.reqBody) } else if (info.method === 'PUT') { return await putAsync(ApiURL, info.reqHeaders, info.reqBody) } else if (info.method === 'PATCH') { return await patchAsync(ApiURL, info.reqHeaders, info.reqBody) } else if (info.method === 'DELETE') { return await deleteAsync(ApiURL, info.reqHeaders) } } catch (err) { return err } };