/** * Send an email listing the top posts every Sunday. */ function startWeeklyTopPostEmailer() { // Run this job every Sunday at 2:30pm. schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function () { // List the top 5 posts. // [START top_posts_query] const topPostsRef = firebase.database().ref('/posts').orderByChild('starCount').limitToLast(5); // [END top_posts_query] const allUserRef = firebase.database().ref('/users'); Promise.all([topPostsRef.once('value'), allUserRef.once('value')]).then(function(resp) { const topPosts = resp[0].val(); const allUsers = resp[1].val(); const emailText = createWeeklyTopPostsEmailHtml(topPosts); sendWeeklyTopPostEmail(allUsers, emailText); }).catch(function(error) { console.log('Failed to start weekly top posts emailer:', error); }); }); console.log('Weekly top posts emailer started...'); }
/** * Sends the weekly top post email to all users in the given `users` object. */ function sendWeeklyTopPostEmail(users, emailHtml) { Object.keys(users).forEach(function(uid) { const user = users[uid]; if (user.email) { const mailOptions = { from: '"Firebase Database Quickstart" <noreply@firebase.com>', to: user.email, subject: 'This week\'s top posts!', html: emailHtml }; mailTransport.sendMail(mailOptions).then(function() { console.log('Weekly top posts email sent to: ' + user.email); // Save the date at which we sent the weekly email. // [START basic_write] return firebase.database().ref().child('/users/' + uid + '/lastSentWeeklyTimestamp') .set(firebase.database.ServerValue.TIMESTAMP); // [END basic_write] }).catch(function(error) { console.log('Failed to send weekly top posts email:', error); }); } }); }
const userRef = firebase.database().ref('/users/' + uid); userRef.once('value').then(function(snapshot) { const email = snapshot.val().email; update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);
app.put('/:id', (req: any, res: any, next: any) => { admin.database().ref('/contacts/' + req.params.id).update({ firstname: req.body.firstname, lastname: req.body.lastname, phone: req.body.phone, email: req.body.email }) res.send(req.body) next() })
addCallHistory(provider, data) { const callHistoryRef = app.locals.db.ref('/call-history/' + provider + '/'); callHistoryRef.push(data) .then(() => { console.log('Call history added!', data); }) .catch(console.error); }
function initializeApp() { parrotDatabaseAdmin=admin.initializeApp(parrotAdmin,"parrotAdmin") database=parrotDatabaseAdmin.database().ref(); }
app.get('/:id', (req: any, res: any, next: any) => { admin.database().ref('/contacts/' + req.params.id).once('value', (data) => { var sn = data.val() res.send({ 'res': sn }) next() },(err: any) => res.send({res: err}) ) })
functions.database.ref('todos').onWrite((snapshot, context) => { const email = context.auth.token.email; const result = snapshot.after.val(); let lastValue = {}; for (const prop in result) { lastValue = {id: prop, value: result[prop]} } admin.database().ref('replicateTodos').child(lastValue.id).set({description: lastValue.value.description , status: lastValue.value.status , title: lastValue.value.title, email: email }) })
/** * Send an email listing the top posts every Sunday. */ function startWeeklyTopPostEmailer() { // Run this job every Sunday at 2:30pm. schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function () { // List the top 5 posts. // [START top_posts_query] const topPostsRef = firebase.database().ref('/posts').orderByChild('starCount').limitToLast(5); // [END top_posts_query] const allUserRef = firebase.database().ref('/users'); Promise.all([topPostsRef.once('value'), allUserRef.once('value')]).then(function(resp) { const topPosts = resp[0].val(); const allUsers = resp[1].val(); const emailText = createWeeklyTopPostsEmailHtml(topPosts); sendWeeklyTopPostEmail(allUsers, emailText); }).catch(function(error) { console.log('Failed to start weekly top posts emailer:', error); }); }); console.log('Weekly top posts emailer started...'); }
/** * Sends the weekly top post email to all users in the given `users` object. */ function sendWeeklyTopPostEmail(users, emailHtml) { Object.keys(users).forEach(function(uid) { const user = users[uid]; if (user.email) { const mailOptions = { from: '"Firebase Database Quickstart" <noreply@firebase.com>', to: user.email, subject: 'This week\'s top posts!', html: emailHtml }; mailTransport.sendMail(mailOptions).then(function() { console.log('Weekly top posts email sent to: ' + user.email); // Save the date at which we sent the weekly email. // [START basic_write] return firebase.database().ref().child('/users/' + uid + '/lastSentWeeklyTimestamp') .set(firebase.database.ServerValue.TIMESTAMP); // [END basic_write] }).catch(function(error) { console.log('Failed to send weekly top posts email:', error); }); } }); }
const userRef = firebase.database().ref('/users/' + uid); userRef.once('value').then(function(snapshot) { const email = snapshot.val().email; update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);
app.put('/:id', function (req, res, next) { admin.database().ref('/contacts/' + req.params.id).update({ firstname: req.body.firstname, lastname: req.body.lastname, phone: req.body.phone, email: req.body.email }); res.send(req.body); next(); });
app.get('/:id', (req: any, res: any, next: any) => { admin.database().ref('/contacts/' + req.params.id).once('value', (data) => { var sn = data.val() res.send({ 'res': sn }) next() },(err: any) => res.send({res: err}) ) })