-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
91 lines (79 loc) · 1.86 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
80
81
82
83
84
85
86
87
88
89
90
91
const express = require('express');
const ejs = require('ejs');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
const PORT = process.env.PORT||3000;
app.set('view engine','ejs');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }));
// Connection to DataBase
mongoose.connect('mongodb:https://localhost:27017/clubstopDB');
// ClubSchema
const ClubSchema = {
Name:String,
Category:String,
Desription:String,
Team:Object,
Acronym:String,
Links:Object
}
// TeamSchema
const teamScehma = {
Name:String,
Role:String
}
const User = mongoose.model("User",teamScehma)
const Club = mongoose.model("Club",ClubSchema);
// Create a demo club
app.get("/newclub",(req,res)=>{
const u1 = new User({
Name:"Micheal",
Role:"Manager"
});
const u2 = new User({
Name:"Dwight",
Role:"ARM"
});
const u3 = new User({
Name:"Jim",
Role:"CoManager"
});
const u4 = new User({
Name:"Pam",
Role:"Receptionist"
});
const c1 = new Club({
Name:"Dunder Mifflin",
Acronym:"DMPC",
Desription:"An office workspace",
Team:[u1,u2,u3,u4]
})
c1.save();
console.log("New Club saved");
res.send("Club Added");
});
app.get("/dm",(req,res)=>{
Club.findOne({"Name":"Dunder Mifflin"},(err,club)=>{
if(err){
console.log(err);
}else{
console.log(club);
res.render("club",{
C_name:club.Name,
C_sf:club.Acronym,
C_des:club.Desription,
team:club.Team
})
}
})
});
app.get("/",(req,res)=>{
res.render("welcome");
})
app.get("/home",(req,res)=>{
res.render("home");
})
app.listen(PORT,()=>{
console.log("App Running on 3000");
})