Skip to content

Instantly share code, notes, and snippets.

@eddwinpaz
Created March 17, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddwinpaz/29d92c5c598df2c0684fabf80eac0c31 to your computer and use it in GitHub Desktop.
Save eddwinpaz/29d92c5c598df2c0684fabf80eac0c31 to your computer and use it in GitHub Desktop.
serviceGetOrderByOrderId
const serviceGetOrderByOrderId = async (fastify, request) => {
// decode base64 and parse to JSON object
// console.log("==== serviceGetOrderByOrderId ====");
// console.log(request);
// console.log("========");
const {
message: {
attributes: { entityType, entityId, siteId, country },
data: data
}
} = request.body;
let orderId = await extractOrderId(entityType, entityId, data);
// Append orderId value with collected data to new request
let requestOrderDomain = request;
requestOrderDomain.params.orderId = orderId;
requestOrderDomain.headers["x-site-id"] = siteId;
requestOrderDomain.headers["Host"] = `.${country.toLowerCase()}`;
// set retry count
let retryCount = 3;
let response;
// Step up to collect good response from external service
for (let i = 1; i <= retryCount; i++) {
console.log("RUNNING=", i);
// Make external service request
response = await getOrdersByOrderId(fastify, requestOrderDomain);
// Validate that the response object exists and check its http code status
// if not same break
if (response) break;
}
return response ? response : "";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment