Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ghardin137/f811f8b96b37370c84b51f429b2ddb1b to your computer and use it in GitHub Desktop.
Save ghardin137/f811f8b96b37370c84b51f429b2ddb1b to your computer and use it in GitHub Desktop.
help.
const menuAndCategory = [
{
menu_name: "First Menu",
menu_description: "I love menus and everything it brings me ",
menu_unique_menu_id: "7d491498-8702-41ba-af53-4dff90f46fc8",
category_name: "Breakfast",
unique_category_id: "71f317cb-6376-4435-ba6c-3a57d006bca6",
product_id: "eda57dcf-234f-423a-9ee3-433e8264ab91",
},
{
menu_name: "First Menu",
menu_description: "I love menus and everything it brings me ",
menu_unique_menu_id: "7d491498-8702-41ba-af53-4dff90f46fc8",
category_name: "Breakfast",
unique_category_id: "71f317cb-6376-4435-ba6c-3a57d006bca6",
product_id: "b39bede4-d02e-46c2-a1d5-ba04c3389f4d",
},
{
menu_name: "First Menu",
menu_description: "I love menus and everything it brings me ",
menu_unique_menu_id: "7d491498-8702-41ba-af53-4dff90f46fc8",
category_name: "Dinner",
unique_category_id: "5a20739e-5614-4166-9f46-64a285e006a0",
product_id: "eda57dcf-234f-423a-9ee3-433e8264ab91",
},
{
menu_name: "First Menu",
menu_description: "I love menus and everything it brings me ",
menu_unique_menu_id: "7d491498-8702-41ba-af53-4dff90f46fc8",
category_name: "Dinner",
unique_category_id: "5a20739e-5614-4166-9f46-64a285e006a0",
product_id: "b39bede4-d02e-46c2-a1d5-ba04c3389f4d",
},
];
const categoryAndProduct = [
{
category_id: "71f317cb-6376-4435-ba6c-3a57d006bca6",
product_name: "Cinnabun Product",
product_description:
"i love so many of these different types of products",
product_ingredients: "Tasty and fun",
unique_product_id: "eda57dcf-234f-423a-9ee3-433e8264ab91",
product_s3_link:
"https://halalbucket21710-dev.s3.amazonaws.com/public/Screen+Shot+2023-05-04+at+8.36.52+PM.png/3e48b5f4-6f40-4df5-ba8e-122db74df57d",
},
{
category_id: "71f317cb-6376-4435-ba6c-3a57d006bca6",
product_name: "Chocholate",
product_description: "I love chocholate chip",
product_ingredients: "Its made with cocoo and vanilla",
unique_product_id: "b39bede4-d02e-46c2-a1d5-ba04c3389f4d",
product_s3_link:
"https://halalbucket21710-dev.s3.amazonaws.com/public/Screen+Shot+2023-05-04+at+8.36.52+PM.png/3e48b5f4-6f40-4df5-ba8e-122db74df57d",
},
{
category_id: "5a20739e-5614-4166-9f46-64a285e006a0",
product_name: "Cinnabun Product",
product_description:
"i love so many of these different types of products",
product_ingredients: "Tasty and fun",
unique_product_id: "eda57dcf-234f-423a-9ee3-433e8264ab91",
product_s3_link:
"https://halalbucket21710-dev.s3.amazonaws.com/public/Screen+Shot+2023-05-04+at+8.36.52+PM.png/3e48b5f4-6f40-4df5-ba8e-122db74df57d",
},
{
category_id: "5a20739e-5614-4166-9f46-64a285e006a0",
product_name: "Chocholate",
product_description: "I love chocholate chip",
product_ingredients: "Its made with cocoo and vanilla",
unique_product_id: "b39bede4-d02e-46c2-a1d5-ba04c3389f4d",
product_s3_link:
"https://halalbucket21710-dev.s3.amazonaws.com/public/Screen+Shot+2023-05-04+at+8.36.52+PM.png/3e48b5f4-6f40-4df5-ba8e-122db74df57d",
},
];
const menus = {};
const categories = {};
const products = {};
menuAndCategory.forEach(category => {
const {
menu_unique_menu_id,
menu_name,
menu_description,
unique_category_id,
category_name
} = category;
if(!menus[menu_unique_menu_id]) {
menus[menu_unique_menu_id] = {
menu_unique_menu_id,
menu_name,
menu_description,
categories: [],
};
}
if(!categories[unique_category_id]) {
categories[unique_category_id] = {
unique_category_id,
category_name,
products: [],
};
}
menus[menu_unique_menu_id].categories.push(unique_category_id);
});
categoryAndProduct.forEach(product => {
const {
product_name,
product_description,
product_ingredients,
unique_product_id,
category_id,
} = product;
if(!products[unique_product_id]) {
products[unique_product_id] = {
product_name,
product_description,
product_ingredients,
unique_product_id,
};
}
if(categories[category_id]) {
categories[category_id].products.push(unique_product_id);
}
});
const mapsForJSON = Object.values(menus).map((menu) => {
return {
...menu,
categories: menu.categories.map((categoryId) => {
const category = categories[categoryId];
return {
...categories,
products: category.products.map((productId) => {
return products[productId]
})
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment