I have successfully added a row in a table called "order" that has the user information, I would like to add the items details individually to a separate table called "order_storeItems" that will be a relationship between the order table and the storeItems table. I tried map using "Promise.all" but it doesn't insert any item to the "order_storeItems". I have no clue on how to go about doing this. Help.
const saveOrder = async () => {
const {data, error} = await supabase.from("order")
.insert([{
user_id: user.id,
username: user.username,
full_name: user.full_name,
email: user.email,
phone_no: user.phone_no,
location: user.location,
}],
{returning: data}
)
;
console.log( data[0]?.id)
await Promise.all(
cart.map((item) =>
supabase.from("order_storeItems")
.insert([{
item_id: item.storeItem_id.id,
user_id: user.id,
delivery_to: nigeriaStates,
pick_up_point: motorPark,
price: item.storeItem_id.price,
quantity: item?.quantity,
sub_total: subTotal,
grand_total: grandTotal,
escrow_fee: escrowFee,
order_id: data[0]?.id,
}])
)
)
};