Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to insert shopping cart items to supabase

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,
                }])
            )
        )

        
    };
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The problem was from my database. Error was showing "value in column "id" of relation "order_storeItems" violates not-null constraint". So i had to give the id column the ability to generate uuid. Thanks for the input.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!