Merge pull request #318 from Safelite/feature/digital/SSR-478
update to payload for serviceability details call
This commit is contained in:
commit
41480bb028
1 changed files with 32 additions and 4 deletions
|
|
@ -553,13 +553,30 @@ export const useMainStore = defineStore({
|
||||||
return availableLineItems;
|
return availableLineItems;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
getServiceabilityDetails({ serviceZipCode }) {
|
getServiceabilityDetails({ serviceZipCode }) {
|
||||||
const lineItemsToSend = this.order.lineItems.supportingItems;
|
const lineItemsWithOnlyPartNumbers = this.order.lineItems.glassParts.map(
|
||||||
const encodedLineItems = encodeURIComponent(JSON.stringify(lineItemsToSend));
|
(glassPart) => ({
|
||||||
|
partNumber: glassPart.partNumber,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const lineItems = buildQueryStringParameterFromArrayOfComplexObjects(
|
||||||
|
lineItemsWithOnlyPartNumbers,
|
||||||
|
"lineItems"
|
||||||
|
);
|
||||||
|
|
||||||
|
const vehicle = this.order.vehicle;
|
||||||
|
const carId = vehicle.carId;
|
||||||
|
const damage = this.order.damage;
|
||||||
|
const glassArray = convertGlassPieceNamingForApi(damage.glassToReplace);
|
||||||
|
|
||||||
|
const glassPieces = buildQueryStringParameterFromArrayOfComplexObjects(
|
||||||
|
glassArray,
|
||||||
|
"glassPieces"
|
||||||
|
);
|
||||||
|
|
||||||
return globalMethods.callHttpClient({
|
return globalMethods.callHttpClient({
|
||||||
method: endpoints.GetServiceabilityDetails.method,
|
method: endpoints.GetServiceabilityDetails.method,
|
||||||
endpoint: `${endpoints.GetServiceabilityDetails.url}?zip=${serviceZipCode}&lineItems=${encodedLineItems}`
|
endpoint: `${endpoints.GetServiceabilityDetails.url}?zip=${serviceZipCode}&carId=${carId}&${lineItems}&${glassPieces}`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1380,3 +1397,14 @@ function getLineItemQueryStringForPricing(lineItems){
|
||||||
}).join('');
|
}).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildQueryStringParameterFromArrayOfComplexObjects(arrayOfObjects, parameterName) {
|
||||||
|
let queryStringParameter = "";
|
||||||
|
for (let i = 0; i < arrayOfObjects.length; i++) {
|
||||||
|
for (const [key, value] of Object.entries(arrayOfObjects[i])) {
|
||||||
|
queryStringParameter += `${parameterName}[${i}].${key}=${value}&`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove trailing &
|
||||||
|
return queryStringParameter.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue