const handles = [
"aerodynamic-granite-coat",
"aerodynamic-plastic-keyboard",
"awesome-iron-computer",
"aerodynamic-granite-coat",
"aerodynamic-plastic-keyboard",
"awesome-iron-computer"
];
const uniqueHandles = Array.from([...new Set(handles)]);
function getProductByHandle(handle, promisies = []){
return Promise.all([
fetch(`https://savchukoleksii.myshopify.com/products/${handle}.json`)
.then(res => res.json())
.then(data => data["product"]),
...promisies
]).then(response => {
const [product, ...rest] = response
return {
...product,
...rest.reduce((responses, response) => ({
...responses,
...response
}), {})
}
})
}
const productsWithAdditional = await Promise.all(uniqueHandles.map(handle => {
return getProductByHandle(handle, [
fetch(`https://savchukoleksii.myshopify.com/products/${handle}?view=json`)
.then(res => res.json())
])
}))