-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
79 lines (66 loc) · 2.24 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const mongoose = require('mongoose')
const express = require('express')
const bodyParser = require('body-parser')
var cors = require('cors')
// Import Routes and Keys
const authRoutes = require('./routes/routes.auth')
const eventRoutes = require('./routes/routes.events')
const quizRoutes = require('./routes/routes.quiz')
const keys = require('./keys')
// Import DB Models
const { Users } = require('./models/users')
const { Events } = require('./models/events')
const { Participants } = require('./models/participants')
const { Teams } = require('./models/teams')
const { Quiz } = require('./models/quiz')
mongoose.connect(keys.mongo.url, { useNewUrlParser: true, useCreateIndex: true }, () => console.log('DB Connected'))
var app = express()
app.use(cors())
// app.use(bodyParser.urlencoded({ extended: true }))
// app.use(bodyParser.json())
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }))
app.use('/auth', authRoutes)
app.use('/events', eventRoutes)
app.use('/quiz', quizRoutes)
app.get('/', (req, res) => {
res.send('Site Working')
})
app.get('/departments', (req, res) => {
Teams.find({}).then(teams => {
res.send(teams)
})
})
app.post('/departments', (req, res) => {
Teams.findById(req.body.clubId)
.then(team => {
// Replace EventIDs with actual event details
var noOfEvents = team.events.length
var counter = 0;
team.events.forEach((eventId, index) => {
Events.findById(eventId)
.then(event => {
counter++;
team.events[index] = event
if (counter === noOfEvents) {
res.send(team)
}
})
})
}).catch(e => res.send('Club Not Found'))
})
// Below Code is for build phase ONLY
// app.get('/participants', (req, res) => {
// Participants.find({})
// .then(participants => {
// res.send(participants)
// })
// })
// app.get('/users', (req, res) => {
// Users.find({})
// .then(users => {
// res.send(users)
// })
// })
// Delete Above Code before launching
module.exports = app;