Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created March 28, 2023 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/542643b5433651e7b5e10c9033682958 to your computer and use it in GitHub Desktop.
Save DominicFinn/542643b5433651e7b5e10c9033682958 to your computer and use it in GitHub Desktop.
Event handlers handling fire store documents create / updated
const functions = require("firebase-functions");
const IterableDataService = require('../../iterable/IterableDataService');
module.exports = functions.firestore.document('prospecting-student/{email}').onCreate(async (snap, context) => {
const student = snap.data();
const result = await IterableDataService.putUserData({
email: snap.id,
userId: student.uuid,
dataFields: {
emailOptIn: true,
isProspectingUser: 'true', // specifically not overwriting userType because some users will already exist
addressable: true,
campaigns: student.campaigns
}
});
functions.logger.info('Iterable putUserData result', result);
return true;
});
const functions = require("firebase-functions");
const IterableDataService = require('../../iterable/IterableDataService');
module.exports = functions.firestore.document('prospecting-student/{email}').onUpdate(async (change, context) => {
const student = change.after.data();
const result = await IterableDataService.putUserData({
email: change.after.id,
userId: student.uuid,
dataFields: {
emailOptIn: true,
isProspectingUser: 'true', // specifically not overwriting userType because some users will already exist
addressable: true,
campaigns: student.campaigns
}
});
// functions.logger.info('Iterable putUserData result', result);
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment