Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. const data = this.cliente
  2.  
  3. const counterRef = this.$firestore.collection('contadores').doc('clientes_motos')
  4. const clientesRef = this.$firestore.collection('clientes/motos/activos')
  5.  
  6. return this.$firestore.runTransaction(transaction => {
  7. return transaction.get(counterRef).then(counterDoc => {
  8. if (!counterDoc.exists) {
  9. throw new Error('No se encontrĂ³ el contador de clientes')
  10. }
  11. const next = counterDoc.data().numero + 1
  12. return clientesRef
  13. .doc(next.toString())
  14. .set(data)
  15. .then(() => {
  16. return transaction.update(counterRef, { numero: next })
  17. })
  18. })
  19. }).then(() => {
  20. // hacer algo al finalizar la transaccion
  21. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement