function showAll (req, res) { return firestore.collection('forms') .get() .then(formsSnapshot => { return formsSnapshot.docs.map(formDoc => formDoc.data()); }) .then(forms => { if (req.query.type == 'json') { return res.json(forms); } res.render('forms', {forms}); }) };
}).then(() => { // send email notification const entriesCollectionRef = firestore.collection(`forms/${formId}/entries`); return entriesCollectionRef.get().then(entriesCollectionSnapshot => { let toAddress = form.notifyEmail; // if notify email address is to be mapped to a field if (form.notifyEmailType && form.notifyEmailType === 'field') { toAddress = content[form.notifyEmail]; } mailer.send(mailer.parse(content), { from: form.fromName + ' <' + form.fromEmail + '>', to: toAddress, cc: form.notifyEmailCc || '', subject: form.notifySubject + ' #' + entriesCollectionSnapshot.size, replyTo: content.name + ' <' + content.email + '>' }); }); });
return formRef.get().then(formSnapshot => { if (!formSnapshot.exists) { return res.sendStatus(404); } return firestore.collection(`forms/${formId}/entries`) .get() .then(entriesSnapshot => { return entriesSnapshot.docs.map(entryDoc => entryDoc.data()); }) .then(entries => { const form = formSnapshot.data(); form.entries = entries; if (req.query.type == 'json') { return res.json(form); } res.render('form_single', form); }); });