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

377
Vistas
Firestore Transaction callback must return a promise ERROR

I've been trying to get this firestore transaction to run but it always throws the same error. I've tried adding a return in the txn.get an txn.set and txn.update, yet it never works.

Here's the transaction I'm trying to get to work:

return db.runTransaction((txn) => {
  // - - - Update inventory - - -
  Products.forEach((product) => {
    // Get existing product (if it exists)
    const docref = db
      .collection("Inventory")
      .doc(product.Description + product.Batch);
    return txn.get(docref).then((doc) => {
      if (doc.exists) {
        // Update values
        const previous_amount = Number(doc.data().Cantidad);
        const new_amount = 0;
        if (MovementType == "Entrada") {
          new_amount = previous_amount + product.Quantity;
        } else {
          new_amount = previous_amount - product.Quantity;
        }
        txn.update(docref, { Cantidad: new_amount });
      } else if (MovementType == "Entrada") {
        // Create document
        txn.set(docref, {
          Articulo: product.Description,
          Cantidad: Number(product.Quantity),
          Precio: product.Subtotal,
          Lote: product.Batch,
          FechaDeIngreso: new Date().toISOString(),
          FechaDeCaducidad: product.ExpiryDate,
        });
      }
    });
  });

  // - - - Register Movement - - -
  const movementDocRef = db.collection("Movimientos").doc();
  txn.set(movementDocRef, {
    MovementType: MovementType,
    Person: Person,
    Products: Products,
    Date: new Date().toISOString(),
    Cfdi: Cfdi != null ? Cfdi.Id : null,
  });
});
about 4 years ago · Juan Pablo Isaza
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