Complete submit game feature
parent
49aff3f741
commit
12c39e271e
|
@ -1,31 +1,28 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var database = require('../database/database');
|
||||
var genders = require('../database/scores/genders');
|
||||
var games = require('../database/scores/games');
|
||||
var moment = require('moment');
|
||||
|
||||
/* GET submit page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
const date_ob = new Date();
|
||||
const date = ("0" + date_ob.getDate()).slice(-2);
|
||||
const month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
|
||||
const year = date_ob.getFullYear();
|
||||
|
||||
const currentDate = year + '-' + month + '-' + date;
|
||||
res.render('submit', { title: 'Submit Score', date: currentDate });
|
||||
res.render('submit', { title: 'Submit Score', date: moment().format('YYYY-MM-DD') });
|
||||
});
|
||||
|
||||
/* POST submit page. */
|
||||
router.post('/', function(req, res, next) {
|
||||
const year = req.body['year'];
|
||||
const sport = req.body['sport'];
|
||||
const gender = req.body['gender'];
|
||||
const division = req.body['division'];
|
||||
const date = req.body['date'];
|
||||
const team1 = req.body['team1'];
|
||||
const seasonID = req.body['year'];
|
||||
const sportID = req.body['sport'];
|
||||
const gender = (req.body['gender'] == "female") ? genders.FEMALE : genders.MALE;
|
||||
const divisionID = req.body['division'];
|
||||
const date = moment(req.body['date']);
|
||||
const team1ID = req.body['team1'];
|
||||
const team1Score = req.body['team1-score'];
|
||||
const team2 = req.body['team2'];
|
||||
const team2ID = req.body['team2'];
|
||||
const team2Score = req.body['team2-score'];
|
||||
|
||||
|
||||
games.add(divisionID, seasonID, date, team1ID, team2ID, team1Score, team2Score)
|
||||
.then(res.send("SUCCESS"));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
Reference in New Issue