Skip to content

Commit

Permalink
Add print statements to firestore function (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri authored Sep 25, 2018
1 parent 292308b commit fcb7ed7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 12 additions & 4 deletions functions/firebase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ exports.helloRTDB = (event, callback) => {
exports.helloFirestore = (event, callback) => {
const triggerResource = event.resource;

// We're just going to log the resource string and the
// full event to prove that it worked.
console.log(`Function triggered by change to: ${triggerResource}`);
console.log(JSON.stringify(event));
console.log(`Function triggered by event on: ${triggerResource}`);
console.log(`Event type: ${event.eventType}`);

if (event.data.oldValue && Object.keys(event.data.oldValue).length) {
console.log(`\nOld value:`);
console.log(JSON.stringify(event.data.oldValue, null, 2));
}

if (event.data.value && Object.keys(event.data.value).length) {
console.log(`\nNew value:`);
console.log(JSON.stringify(event.data.value, null, 2));
}

// Don't forget to call the callback.
callback();
Expand Down
13 changes: 9 additions & 4 deletions functions/node8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,17 @@ exports.helloFirestore = (data, context) => {
const triggerResource = context.resource;

console.log(`Function triggered by change to: ${triggerResource}`);
console.log(`Event type: ${context.eventType}`);

console.log(`\nOld value:`);
console.log(JSON.stringify(data.oldValue, null, 2));
if (data.oldValue && Object.keys(data.oldValue).length) {
console.log(`\nOld value:`);
console.log(JSON.stringify(data.oldValue, null, 2));
}

console.log(`\nNew value:`);
console.log(JSON.stringify(data.value, null, 2));
if (data.value && Object.keys(data.value).length) {
console.log(`\nNew value:`);
console.log(JSON.stringify(data.value, null, 2));
}
};
// [END functions_firebase_firestore_node8]

Expand Down

0 comments on commit fcb7ed7

Please sign in to comment.