Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make firestore function work for all trigger types #742

Merged
merged 3 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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