-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
924 lines (895 loc) · 30.5 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
//===============SEMS app====================
const express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
flash = require("connect-flash"),
//seedDB = require("./seed"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose"),
User = require("./models/user"),
NewMember = require("./models/newMember"),
Notification = require("./models/notification"),
Shift = require("./models/shift"),
methodOverride = require("method-override"),
crypto = require("crypto"),
request = require('request'),
nodemailer = require("nodemailer"),
schedule = require('node-schedule');
const indexRoutes = require("./routes/index"),
userRoutes = require("./routes/user"),
shiftRoutes = require("./routes/shift"),
guideRoutes = require("./routes/guide"),
adminRoutes = require("./routes/admin"),
documentRoutes = require("./routes/document");
var nodeoutlook = require('nodejs-nodemailer-outlook')
//Add seed data
//seedDB();
mongoose.connect(process.env.DATABASEURL, {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false });
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
app.use(methodOverride("_method"));
app.use(flash());
app.use(require("express-session")({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(function(req, res, next) {
res.locals.currentUser = req.user;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
});
// //=====================
// //NodeMailer
// //=====================
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: process.env.MAILUSER,
clientId: process.env.MAILID,
clientSecret: process.env.MAILSECRET,
refreshToken: process.env.MAILREFRESH,
accessToken: process.env.MAILACCESS
}
});
// //=====================
// //Node-Schedule
// * * * * * *
// ┬ ┬ ┬ ┬ ┬ ┬
// │ │ │ │ │ │
// │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
// │ │ │ │ └───── month (1 - 12)
// │ │ │ └────────── day of month (1 - 31)
// │ │ └─────────────── hour (0 - 23)
// │ └──────────────────── minute (0 - 59)
// └───────────────────────── second (0 - 59, OPTIONAL)
// //=====================
//Find shifts that took place the previous day, get their members and hours, and add the hours to the currentMonth's hours for each member on the shift.
var updateCurrentMonth = schedule.scheduleJob('0 0 0 * * *', async function(){
var today = new Date();
var yyyy = today.getFullYear();
var mm = today.getMonth()+1;
var dd = today.getDate();
var todaySet = new Date(yyyy+"/"+mm+"/"+dd);
var todayMS = todaySet.getTime();
var yesterdayMS = todayMS - 86400000;
var allShifts = await Shift.find();
allShifts.forEach(async function(shift){
if(shift.startDateMS == yesterdayMS){
if(shift.type == "es" || shift.type == "dc" || shift.type == "ta"){
if(shift.officerInCharge.name){
await User.findById(shift.officerInCharge._id).then(async function(user){
var durationHours = shift.duration/3600000;
var updatedHours = parseFloat(durationHours.toFixed(2)) + user.hours.currentMonth;
var hoursPush = {
currentMonth: updatedHours,
currentSem: user.hours.currentSem,
semesterTotals: user.hours.semesterTotals,
monthlyTotals: user.hours.monthlyTotals,
totalHours: user.hours.totalHours
}
await User.updateOne({_id: user.id}, {$set:{hours: hoursPush}}), (function(err){if (err){console.log(err.message)}})
})
}
if(shift.crewChief.name){
await User.findById(shift.crewChief._id).then(async function(user){
var durationHours = shift.duration/3600000;
var updatedHours = parseFloat(durationHours.toFixed(2)) + user.hours.currentMonth;
var hoursPush = {
currentMonth: updatedHours,
currentSem: user.hours.currentSem,
semesterTotals: user.hours.semesterTotals,
monthlyTotals: user.hours.monthlyTotals,
totalHours: user.hours.totalHours
}
await User.updateOne({_id: user.id}, {$set:{hours: hoursPush}}, function(err){if (err){console.log(err.message)}})
})
}
if(shift.crewArray != undefined || shift.crewArray != null || shift.crewArray != 0){
shift.crewArray.forEach(async function(crew){
await User.findById(crew._id).then(async function(user){
var durationHours = shift.duration/3600000;
var updatedHours = parseFloat(durationHours.toFixed(2)) + user.hours.currentMonth;
var hoursPush = {
currentMonth: updatedHours,
currentSem: user.hours.currentSem,
semesterTotals: user.hours.semesterTotals,
monthlyTotals: user.hours.monthlyTotals,
totalHours: user.hours.totalHours
}
await User.updateOne({_id: user.id}, {$set:{hours: hoursPush}}, function(err){if (err){console.log(err.message)}})
})
})
}
}
}
})
});
//Send an email reminder to everyone that is supposed to be on the shift
var sendReminder = schedule.scheduleJob('0 0 8 * * *', async function(){
var today = new Date();
var yyyy = today.getFullYear();
var mm = today.getMonth()+1;
var dd = today.getDate();
var todaySet = new Date(yyyy+"/"+mm+"/"+dd);
var todayMS = todaySet.getTime();
var tomorrowMS = todayMS + 86400000;
var shifts = await Shift.find({startDateMS: tomorrowMS});
if(shifts){
shifts.forEach(async function(shift){
if(shift.type == "es" && shift.status == "scheduled"){
await User.findById(shift.officerInCharge._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Event Standby Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's event standby for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This event will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Event Standby Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's event standby for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This event will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
await User.findById(shift.crewChief._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Event Standby Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's event standby for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This event will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Event Standby Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's event standby for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This event will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
await shift.crewArray.forEach(async function(crew){
if(crew){
var user = await User.findById(crew._id);
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Event Standby Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's event standby for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This event will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Event Standby Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's event standby for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This event will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
} else if(shift.type == "dc" && shift.status == "scheduled"){
if(shift.officerInCharge.name){
await User.findById(shift.officerInCharge._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Duty Crew Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's duty crew. \n\n"
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This duty crew will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Duty Crew Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's duty crew. \n\n"
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This duty crew will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
}
if(shift.crewChief.name){
await User.findById(shift.crewChief._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Duty Crew Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's duty crew. \n\n"
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This duty crew will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Duty Crew Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's duty crew. \n\n"
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This duty crew will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
}
)
}
if(shift.crewArray != undefined || shift.crewArray != null || shift.crewArray != 0){
shift.crewArray.forEach(async function(crew){
await User.findById(crew._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Duty Crew Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's duty crew. \n\n"
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ " at "
+ `${shift.reportLocation}`
+ ". This duty crew will take place at/in: "
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ "Stockton EMS Executive Board Auto-generated Email"
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Duty Crew Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's duty crew. \n\n"
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + " at "
// + `${shift.reportLocation}`
// + ". This duty crew will take place at/in: "
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + "Stockton EMS Executive Board Auto-generated Email"
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
})
}
} else if(shift.type == "ta" && shift.status == "scheduled"){
var emailList =[];
if(shift.officerInCharge.name){
await User.findById(shift.officerInCharge._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Tabling Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's tabling event for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ ". Please see the schedule for details."
+ '.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Tabling Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's tabling event for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + ". Please see the schedule for details."
// + '.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
}
if(shift.crewChief.name){
await User.findById(shift.crewChief._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Tabling Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's tabling event for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ ". Please see the schedule for details."
+ '.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Tabling Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's tabling event for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + ". Please see the schedule for details."
// + '.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
}
if(shift.crewArray != undefined || shift.crewArray != null || shift.crewArray != 0){
shift.crewArray.forEach(async function(crew){
await User.findById(crew._id).then(async function(user){
if(user){
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${user.email}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'Tabling Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's tabling event for "
+ `${shift.shiftName}`
+ '.\n\n'
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ ". Please see the schedule for details."
+ '.\n\n'
+ 'Shift Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${user.email}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'Tabling Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's tabling event for "
// + `${shift.shiftName}`
// + '.\n\n'
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + ". Please see the schedule for details."
// + '.\n\n'
// + 'Shift Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log(err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
})
})
}
} else if(shift.type == "gm" && shift.status == "scheduled"){
await User.find({onRoster: true}).then(function(user){
const sendMail = async function(){
var emailList = []
for(var i = 0; i < user.length; i++){
emailList.push(user[i].email)
}
nodeoutlook.sendEmail({
auth: {
user: process.env.MAILEREMAIL,
pass: process.env.MAILERPASS
},
from: process.env.MAILEREMAIL,
to: `${emailList}`,
replyTo: 'stocktonems-club@go.stockton.edu',
subject: 'General Meeting Reminder',
text:
'Hello!\n\n'
+ "This is a reminder about tomorrow's general meeting.\n\n"
+ 'The report time is: '
+ `${shift.shiftStart.reportTime}`
+ ' in '
+ `${shift.shiftLocation}`
+ '. Please see the schedule for more details.\n\n'
+ 'Meeting Notes: '
+ '\n'
+ `${shift.notes}`
+ "\n\n"
+ 'Stockton EMS Executive Board Auto-generated Email'
+ '\n\n'
+ process.env.DOMAIN,
onError: (e) => console.log("Error! "+e),
onSuccess: (i) => console.log("Message sent!")
});
// const mailOptions = {
// from: process.env.MAILEREMAIL,
// to: `${emailList}`,
// replyTo: 'stocktonems-club@go.stockton.edu',
// subject: 'General Meeting Reminder',
// text:
// 'Hello!\n\n'
// + "This is a reminder about tomorrow's general meeting.\n\n"
// + 'The report time is: '
// + `${shift.shiftStart.reportTime}`
// + ' in '
// + `${shift.shiftLocation}`
// + '. Please see the schedule for more details.\n\n'
// + 'Meeting Notes: '
// + '\n'
// + `${shift.notes}`
// + "\n\n"
// + 'Stockton EMS Executive Board Auto-generated Email'
// + '\n\n'
// + process.env.DOMAIN,
// };
// console.log('sending mail');
// await transporter.sendMail(mailOptions, function (err) {
// if (err) {
// console.log("Could not send email: "+err.message)
// } else {
// console.log("Email successfully sent!")
// }
// });
}
sendMail();
})
}
})
}
});
//Saves the currentMonth's hours to the user's monthlyTotals array, adds the currentMonth's hours to the currentSem total, adds the currentMonth's hours to totalHours, and zeroes out the currentMonth value
var updateMonthlyHours = schedule.scheduleJob('5 0 0 1 * *', async function(){
var today = new Date();
var yyyy = today.getFullYear();
var mm = today.getMonth()+1;
var foundUser = await User.find({onRoster:true});
foundUser.forEach(async function(user){
var monthlyTotalPush = {month: mm+"/"+yyyy, hours: user.hours.currentMonth};
await User.updateOne({_id: user.id}, {$addToSet: {monthlyTotals: monthlyTotalPush}});
var hoursPush = {
currentMonth: 0,
currentSem: user.hours.currentSem + user.hours.currentMonth,
totalHours: user.hours.totalHours + user.hours.currentMonth
}
await User.updateOne({_id: user.id}, {$set: {hours: hoursPush}})
});
});
//Save currentSem's total to semesterTotals array and zeroes out the currentSem total
var updateSemesterHours = schedule.scheduleJob('10 0 0 1 1,7 *', async function(){
// 0,30 * * * *
var today = new Date();
var yyyy = today.getFullYear();
var mm = today.getMonth()+1;
var semester;
if(mm>=7){
semester = "Fall "
} else {
semester = "Spring "
};
var foundUser = await User.find({onRoster:true});
foundUser.forEach(async function(user){
var semesterTotalsPush = {semName: semester+yyyy, hours: user.hours.currentSem};
await User.updateOne({_id: user.id}, {$addToSet: {semesterTotals: semesterTotalsPush}});
var hoursPush = {
currentMonth: user.hours.currentMonth,
currentSem: 0,
totalHours: user.hours.totalHours
};
await User.updateOne({_id: user.id}, {$set: {hours: hoursPush}});
});
});
// //=====================
// //Routes
// //=====================
app.use(userRoutes);
app.use(documentRoutes);
app.use(shiftRoutes);
app.use(guideRoutes);
app.use(indexRoutes);
app.use(adminRoutes);
//404 Error Route
app.use(function(req, res, next){
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('noPage', { url: req.url });
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
//Use export PORT=3000
app.listen(process.env.PORT, function(){
console.log("SEMS Member Site has started...");
});