Created
March 16, 2020 08:31
-
-
Save k-saka/40a3dcbb42ba8a2a79a9fc9b01e67894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const testtransaction = async () => { | |
const counterDoc = await customerTotalCounterRef().get() | |
const counter = counterDoc.data() as customerCounter | |
console.warn('before') | |
console.warn(counter.count) | |
try { | |
await db.runTransaction(async transaction => { | |
await transaction.update(customerTotalCounterRef(), { | |
count: firebaseApp.firestore.FieldValue.increment(1), | |
}) | |
throw new errorDM.ValueError() | |
}) | |
} catch (e) { | |
const fcounterDoc = await customerTotalCounterRef().get() | |
const fcounter = fcounterDoc.data() as customerCounter | |
console.warn('failed after') | |
console.warn(fcounter.count) | |
return | |
} | |
const acounterDoc = await customerTotalCounterRef().get() | |
const acounter = acounterDoc.data() as customerCounter | |
console.warn('succeed after') | |
console.warn(acounter.count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment