Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const data = this.cliente
- const counterRef = this.$firestore.collection('contadores').doc('clientes_motos')
- const clientesRef = this.$firestore.collection('clientes/motos/activos')
- return this.$firestore.runTransaction(transaction => {
- return transaction.get(counterRef).then(counterDoc => {
- if (!counterDoc.exists) {
- throw new Error('No se encontrĂ³ el contador de clientes')
- }
- const next = counterDoc.data().numero + 1
- return clientesRef
- .doc(next.toString())
- .set(data)
- .then(() => {
- return transaction.update(counterRef, { numero: next })
- })
- })
- }).then(() => {
- // hacer algo al finalizar la transaccion
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement