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

153
Vistas
Firebase transaction deletes node

When user makes an in-app purchase, I want their tokens count to decrement by the cost. This will just delete the user's tokens

(This code used to work and broke recently)

    var senderRef = db.ref(`users/${sender.id}/tokens`)
    var amount = 1000
    var tokensCount =  await (await senderRef.once('value')).val()
    console.log("SENDER TOKENS: ", tokensCount, sender.id)
    await senderRef.transaction(async function(currentTokens) {
        var newAmount = currentTokens - amount
        if (newAmount >= 0) {
            return newAmount
        } else {
            return 
        }
    }).then(async (result) => {
        var tokensCount = await (await senderRef.once('value')).val()
        console.log("SENDER TOKENS AFTER TRANSACTION: ", tokensCount, sender.id)
    })

I have data structured as: enter image description here

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