Created
January 27, 2019 00:03
-
-
Save hiranya911/69a3c50b24226a20575982312aabba3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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(¤tScore); 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