Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Created January 27, 2019 00:03
Show Gist options
  • Save hiranya911/69a3c50b24226a20575982312aabba3c to your computer and use it in GitHub Desktop.
Save hiranya911/69a3c50b24226a20575982312aabba3c to your computer and use it in GitHub Desktop.
func ScoreReview(ctx context.Context, e FirestoreEvent) error {
review := e.Value.Fields
reviweScore := score(review.Text.Value)
ref := client.NewRef("scores").Child(review.Author.Value)
updateTxn := func(node db.TransactionNode) (interface{}, error) {
var currentScore int
if err := node.Unmarshal(&currentScore); err != nil {
return nil, err
}
return currentScore + reviweScore, nil
}
return ref.Transaction(ctx, updateTxn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment