-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (64 loc) · 2.32 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
import express from 'express';
import bodyParser from 'body-parser';
import events from './routes/events';
import upcomingEvents from './helpers/check-dates';
import getTodaysEvents from './helpers/todaysEvents';
import sendMessage, { sendWithChatApi } from './helpers/messaging';
import path from 'path';
import cors from 'cors';
import nofifyer from 'node-cron';
import './config/passport';
import userRouter from './routes/user';
const port = process.env.PORT || 3000;
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.json());
app.use(cors());
app.use(express.static(path.resolve(__dirname, 'views')));
app.use(express.static(path.resolve(__dirname, 'views/front-end')));
nofifyer.schedule('0 8 * * *', async () => {
const events = await upcomingEvents();
if (events.length) {
events.forEach((event) => {
const message = `Hello ${event.firstname} ${event.lastname} Your ${
event.target
}'s ${event.type} Is happening in ${
event.notificationTime
} days Click https://remembermeplease.herokuapp.com/write-message.html?id=${
event.id
} to write a ${event.type} Message That will be sent on that day`;
sendWithChatApi(message, event.user_phone);
});
}
});
// nofifyer.schedule('* * * * * *', async () => {
// const events = await upcomingEvents();
// events.forEach((event) => {
// const message = `Hello ${event.firstname} ${event.lastname} Your ${
// event.target
// }'s ${event.type} Is happening in ${event.notificationTime} days`;
// sendMessage(message, event.user_phone);
// });
// const todaysEvents = await getTodaysEvents();
// console.log(todaysEvents);
// todaysEvents.forEach((event) => {
// if (event.messages.length === 0) {
// const message = `Hello ${event.firstname} ${event.lastname} Your ${
// event.target
// }'s ${event.type} Is happening in today`;
// console.log(event);
// sendMessage(message, event.User.phonenumber);
// }
// console.log(event);
// })
// });
app.get('/', (req, res) => {
res.json({ message: 'Welcome to remember me please' });
});
app.use('/events', events);
app.use('/user', userRouter);
const server = app.listen(port, () => {
console.log(`server started on port ${port}`);
});
export default server;