/** * 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...'); }
app.post('/api/report/getRoomReports', (req, res) => { // get reference to the rooms checkins history const checkinsRef = db.ref(`rooms/${req.body.roomID}/checkins`); checkinsRef.orderByChild('timestamp').once('value', snapshot => { const checkins = {}; Object.entries(snapshot.val()) .map(([key, val]) => { if (val.hasOwnProperty('endTime') && val.type === 'members') { checkins[key] = val } }); // send back response containing success message // and the rooms checkins history data res.status(200).json({ success: true, message: 'Successfully fetched room checkins', checkins }); }); });
/** * 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...'); }
/** * 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] var topPostsRef = firebase.database().ref('/posts').orderByChild('starCount').limitToLast(5); // [END top_posts_query] var allUserRef = firebase.database().ref('/users'); Promise.all([topPostsRef.once('value'), allUserRef.once('value')]).then(function(resp) { var topPosts = resp[0].val(); var allUsers = resp[1].val(); var 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...'); }