Skip to content

Commit b1eadf9

Browse files
feat: send notification email for upcoming events
1 parent 5588f56 commit b1eadf9

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

server/package-lock.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"express": "^4.17.1",
2020
"jsonwebtoken": "^8.5.1",
2121
"mongoose": "^5.12.9",
22+
"node-cron": "^3.0.0",
2223
"nodemailer": "^6.6.1",
2324
"passport": "^0.4.1",
2425
"passport-google-oauth": "^2.0.0",
@@ -33,6 +34,7 @@
3334
"@types/jsonwebtoken": "^8.5.1",
3435
"@types/mongoose": "^5.10.5",
3536
"@types/node": "^15.0.3",
37+
"@types/node-cron": "^2.0.3",
3638
"@types/nodemailer": "^6.4.2",
3739
"@types/passport": "^1.0.6",
3840
"@types/passport-google-oauth": "^1.0.41",

server/src/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import mongoose from "mongoose";
33
import cors from "cors";
44
import cookieParser from "cookie-parser";
55
import passport from "passport";
6+
import cron from "node-cron";
67

78
import refreshTokenRoute from "./routes/refreshtoken";
89
import userRoute from "./routes/userRoutes";
910
import googleAuthRoutes from "./routes/googleAuthRoutes";
1011
import meetingRoute from "./routes/meetingRoutes";
1112
import pollRoutes from "./routes/pollRoutes";
13+
import { Meeting } from "./model/Meeting";
14+
// import { mailer } from "./config/mailer"; // Uncomment this in production
1215
require("./config/google-oauth");
1316

1417
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -48,6 +51,24 @@ app.get("/", (_, res) => {
4851
res.send("hello world");
4952
});
5053

54+
// EMAIL
55+
cron.schedule("0 0 * * *", async () => {
56+
const data = await Meeting.find();
57+
const tom = new Date();
58+
tom.setDate(tom.getDate() + 1);
59+
data.forEach((e) => {
60+
const date = new Date(e.datetime);
61+
if (date.toISOString() <= tom.toISOString()) {
62+
console.log("sending mail...");
63+
// UNCOMMENT below in production
64+
// const registers = e.registered;
65+
// const earr = registers.map(e=>e.email);
66+
// const emails = earr.join(", ");
67+
// mailer(emails);
68+
}
69+
});
70+
});
71+
5172
// LISTEN
5273
const port = process.env.PORT ? process.env.PORT : 5000;
5374
app.listen(port, () => {

0 commit comments

Comments
 (0)