39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
var express = require('express');
|
|
var mail = require('../mail/mail');
|
|
var router = express.Router();
|
|
|
|
/* GET submit page. */
|
|
router.get('/', function(req, res, next) {
|
|
res.send('Nothing to send');
|
|
});
|
|
|
|
/* POST submit page. */
|
|
router.post('/', function(req, res, next) {
|
|
let sport = req.body.sport;
|
|
let gender = req.body.gender;
|
|
let division = req.body.division;
|
|
let home = req.body['home-team'];
|
|
let homeScore = req.body['home-team-score'];
|
|
let visiting = req.body['visiting-team'];
|
|
let visitingScore = req.body['visiting-team-score'];
|
|
let submitter = req.body['submitter'];
|
|
let recipient = req.body['email'];
|
|
|
|
let message = prepMailBody(sport, gender, division, home, homeScore, visiting, visitingScore, submitter);
|
|
|
|
mail.send(recipient, "Score Report", message);
|
|
|
|
res.send('Score sent');
|
|
});
|
|
|
|
var prepMailBody = function(sport, gender, division, home, homeScore, visiting, visitingScore, submitter) {
|
|
return(
|
|
"Score report from <b>" + submitter + "</b><br><br>" +
|
|
"<b>Sport:</b><br>" + sport + " - " + gender + " - " + division + "<br><br>" +
|
|
"<b>Home team:</b><br>" + home + " - " + homeScore + "<br><br>" +
|
|
"<b>Visiting team:</b><br>" + visiting + " - " + visitingScore + "<br><br>");
|
|
};
|
|
|
|
|
|
module.exports = router;
|