Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda