From 12c39e271e63845819118fa2962e22c3878a06a9 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sun, 21 Nov 2021 17:43:34 -0700 Subject: [PATCH] Complete submit game feature --- routes/submit.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/routes/submit.js b/routes/submit.js index e79ff92..8510303 100644 --- a/routes/submit.js +++ b/routes/submit.js @@ -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;