59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
var express = require('express');
|
|
var router = express.Router();
|
|
var sports = require('../database/scores/sports');
|
|
var seasons = require('../database/scores/seasons');
|
|
var genders = require('../database/scores/genders');
|
|
var divisions = require('../database/scores/divisions');
|
|
var teams = require('../database/scores/teams');
|
|
var games = require('../database/scores/games');
|
|
|
|
|
|
router.get('/sports', function(req, res, next) {
|
|
sports.retrieveAll()
|
|
.then(data => res.json(data));
|
|
});
|
|
|
|
router.get('/sport', function(req, res, next) {
|
|
sports.getFromID(req.query.sport)
|
|
.then(data => res.json(data));
|
|
});
|
|
|
|
router.get('/seasons', function(req, res, next) {
|
|
seasons.retrieveAll()
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/genders', function(req, res, next) {
|
|
genders.retrieveBySport(req.query.sport)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/divisions', function(req, res, next) {
|
|
let gender;
|
|
if(req.query.gender) gender = (req.query.gender == 'female' ? genders.FEMALE : genders.MALE);
|
|
|
|
divisions.retrieve(req.query.sport, gender)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/division', function(req, res, next) {
|
|
divisions.getFromID(req.query.division)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/teams', function(req, res, next) {
|
|
teams.retrieve(req.query.sport)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/team', function(req, res, next) {
|
|
teams.getFromID(req.query.team)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
router.get('/games', function(req, res, next) {
|
|
games.retrieve(req.query.team, req.query.division, req.query.season)
|
|
.then(data => res.json(data));
|
|
})
|
|
|
|
module.exports = router; |