-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
218 lines (177 loc) · 5.18 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
const express = require("express")
const bodyParser = require("body-parser")
const exp = require("constants")
const mongoose = require("mongoose")
const app= express()
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended:true }));
app.use(express.static("public"))
mongoose.connect("mongodb+srv://prakhardeoria2004:[email protected]/todolist", {useNewUrlParser:true}).then(() => {
console.log(`CONNECTED TO MONGO!`);
})
.catch((err) => {
console.log(`OH NO! MONGO CONNECTION ERROR!`);
console.log(err);
})
const itemSchema = {
name:String
}
const workSchema = {
name:String
}
let item = []
let works = []
const Item = mongoose.model("Item",itemSchema)
const Work = mongoose.model("Work",workSchema)
const item1 = new Item({
name:"Cricket"
})
const item2 = new Item({
name:"Coding"
})
const item3 = new Item({
name:"Listening Music"
})
const work1 = new Work({
name:'Doing two Projects'
})
const work2 = new Work({
name:'Doing CP'
})
const work3 = new Work({
name:'Learn App dev'
})
const defaultItem = [item2,item3]
const defaultItem1 = [work1,work2,work3]
// cricket.save()
// Item.insertMany(defaultItem).then((err)=>{
// if(err){
// console.log("Insert succesfully")
// } else{
// console.log("Not Insert in database")
// }
// })
// Item.deleteMany({_id:"646321fcfa559470cef77509"}).then((err)=>{
// if(err){
// console.log("Succesfully Deleted")
// }
// else{
// console.log("Unsuccesful")
// }
// })
// Work.insertMany(defaultItem1).then((err)=>{
// if(err){
// console.log("Insert Succesfully")
// }
// else{
// console.log("Sorry Operation not succesfully")
// }
// })
Item.find().then((data)=>{
data.forEach(function(Data){
item.push(Data.name)
})
})
Work.find().then((data)=>{
data.forEach(function(Data){
works.push(Data.name)
})
})
app.get("/",function(req,res)
{
var today = new Date()
var currentday = today.getDay()
var date = today.getDate()
var month = today.getMonth()
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
var day = ""
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
if(currentday === 6 || currentday === 0){
day = "Weekend"
// res.sendFile(__dirname+'/weekand.html')
}
else{
day = "Weekday"
// res.sendFile(__dirname+"/working.html")
}
res.render('list',{listTitle:"Normal-works", kindOfDay: days[currentday],Dayname: day, Date:Number(date), Month:months[Number(month)], New:item })
})
app.get("/work", function(req,res)
{
var today = new Date()
var currentday = today.getDay()
var date = today.getDate()
var month = today.getMonth()
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
var day = ""
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
if(currentday === 6 || currentday === 0){
day = "Weekend"
}
else{
day = "Weekday"
}
res.render('list',{listTitle:"Work-List",kindOfDay: days[currentday],Dayname: day, Date:Number(date), Month:months[Number(month)], New:works })
})
app.post("/",function(req,res)
{
let input = req.body.newItem;
console.log(req.body.listadd)
if(req.body.listadd === 'Work-List'){
works.push(input)
const work4 = new Work({
name:input
})
let newdata = [work4]
Work.insertMany(newdata).then((err)=>{
if(err){
console.log("Insert Success in workdb")
}else{
console.log("Problem Occur in workdb")
}
})
res.redirect("/work");
}
else if(req.body.listrem === 'Work-List'){
let data = works.pop()
Work.deleteOne({name:data}).then((err)=>{
if(err){
console.log("Succesfully Deleted in workdb")
}
else{
console.log("Unsuccesful in work db")
}
})
res.redirect("/work");
}
else if(req.body.listadd === 'Normal-works'){
item.push(input)
const item4 = new Item({
name:input
})
let newdata = [item4]
Item.insertMany(newdata).then((err)=>{
if(err){
console.log("Insert Success in itemdb")
}else{
console.log("Problem Occur in itemdb")
}
})
res.redirect("/");
}
else{
let data = item.pop()
Item.deleteOne({name:data}).then((err)=>{
if(err){
console.log("Succesfully Deleted in itemdb")
}
else{
console.log("Unsuccesful in itemdb")
}
})
res.redirect("/")
}
})
app.listen(3000,function(){
console.log("Server started")
})