Skip to content

Instantly share code, notes, and snippets.

@e-lin
Created June 26, 2019 08:24
Show Gist options
  • Save e-lin/44dcdcddbd602594ab23b33678697e46 to your computer and use it in GitHub Desktop.
Save e-lin/44dcdcddbd602594ab23b33678697e46 to your computer and use it in GitHub Desktop.
Firestore trigger 1 - send answer to Android Thing
export const onAnswer = functions.firestore.document('/pic/{picId}').onUpdate(_onAnswer)
async function _onAnswer(change: functions.Change<DocumentSnapshot>): Promise<any> {
const picId = change.before.id "//20180624120000"
const previous = change.before.data() as Pic
const pic = change.after.data() as Pic
// Only interested in pics that have a new answer
if (previous.answer || !pic.answer) {
console.log("This is not the update you are looking for.")
return Promise.resolve()
}
}
// cont'd...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment