/** * 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...'); }
userRef.once('value').then(function(snapshot) { const email = snapshot.val().email;
function all() { return Model.once('value').then(function(snapshot) { const data = snapshot.val() if(data){ return utils.makeResponse(200,data) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500,null,error.message) }); }
ref.once('value', snapshot => { // no verification ID, account has consumed token, continue if (!snapshot.exists()) return next(); // if not, account is not verified, res.status(403).json({ success: false, error: 'Account not verified', message: 'Your account needs to be verified to perform this action. Please click the link sent to the account registered e-mail address.' }); });
app.get('/api/v1/address/:key', function(request, response){ if ((request.params || {}).key){ addressRef.child((request.params || {}).key).once('value').then(function(snapshot) { response.send({data: snapshot.val()}); }, function (errorObject) { console.log("The read failed: " + errorObject.code); response.send(errorObject); }); } });
app.get('/:id', function (req, res, next) { admin.database().ref('/contacts/' + req.params.id).once('value', function (data) { var sn = data.val(); res.send({ 'res': sn }); next(); }, function (err) { return res.send({ res: err }); }); });
functions.https.onRequest((request: any, response: any) => { contactsRef.once('value', (data) => { response.send({ 'res': data.val() }) }) })
const getSettings = (organizationId) => { return new Promise((resolve, reject) => { admin.database().ref(`/shipping_carriers/${organizationId}`).once('value').then((snapshot) => { let settings = snapshot.val(); if(!settings) { return reject({code: 404, message: 'Shipping carriers not found for organization'}) } return resolve(settings); }) }); }
function update(id, data) { return Model.child(id).once('value').then((snapshot) =>{ if(snapshot.val()){ Model.child(id).update(data); return utils.makeResponse(200,null) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500, null, error.message) }); }
app.get('/api/v1/address', function(request, response){ addressRef.once('value').then(function(snapshot) { response.send({data: snapshot.val()}); }, function (errorObject) { console.log("The read failed: " + errorObject.code); response.send(errorObject); }); });
/** * 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...'); }
userRef.once('value').then(function(snapshot) { const email = snapshot.val().email;
function all() { return Model.once('value').then(function(snapshot) { const data = snapshot.val() if(data){ return utils.makeResponse(200,data) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500,null,error.message) }); }
function update(id, data) { return Model.child(id).once('value').then((snapshot) =>{ if(snapshot.val()){ Model.child(id).update(data); return utils.makeResponse(200,null) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500, null, error.message) }); }
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}) ) })