Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda