Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event follow and RSVP #38

Open
wants to merge 55 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7779c21
Update enum.js
Oct 16, 2020
19f7926
Update index.ejs
Oct 16, 2020
a7ecf59
Update index.ejs
Oct 16, 2020
7bc23bb
Update event_db.js
Oct 16, 2020
4d830b7
Update event_api.js
Oct 16, 2020
529efe9
Update edit.ejs
Oct 16, 2020
4fec3ed
Create modal.js
Oct 16, 2020
7b438e8
Update edit.ejs
Oct 16, 2020
e9b5ca5
Update edit.ejs
Oct 16, 2020
f12e108
Update edit.ejs
Oct 16, 2020
89c0b03
Update edit.ejs
Oct 16, 2020
8b9c680
Update edit.ejs
Oct 16, 2020
068fca9
Update head.ejs
Oct 16, 2020
5e803cf
Merge branch 'dev' into event-soft-delete
Oct 16, 2020
9167c42
send followed event information for render
Oct 30, 2020
ae64973
query followed events, follow event, and unfollow event
Oct 30, 2020
36de5df
follow event and unfollow event api
Oct 30, 2020
753ed64
follow/unfollow evenet button
Oct 30, 2020
1ea4b25
Allow notification bar to show customized message
Nov 14, 2020
0a7e80c
Page to show a list of followed events
Nov 14, 2020
f5da826
to followed page
Nov 14, 2020
6e33037
RSVP email, email service is temporarily blocked
Nov 14, 2020
7a155d4
Followed event and RSVP button
Nov 14, 2020
150bb62
update notification bar. The color of bar changes depending on s/f va…
Nov 14, 2020
c8a3fa4
background-color is set inside ejs file
Nov 14, 2020
bc2762a
enable email
Nov 14, 2020
bcc6058
not sure if this should be changed
Nov 14, 2020
9c172bd
Update user_db.js
Nov 19, 2020
2319fa4
Update event.js
Nov 19, 2020
d1d1048
Update event.js
Nov 19, 2020
93032ba
Update nav.ejs
Nov 19, 2020
2164118
Update email_service.js
Nov 19, 2020
07f5617
Merge branch 'dev' into event-follow-save
jialuogao Nov 28, 2020
bcf865c
Minor auth update
jialuogao Nov 29, 2020
0779048
Fork a child process to run the rsvp sender
Jan 22, 2021
f37160a
Create rsvp_sender.js
Jan 22, 2021
4993d2b
Change RSVP related events from GET to POST
Jan 22, 2021
24b3d07
Get user's email by provided user_id
Jan 22, 2021
4ea1f3a
Get user's followed events by user id
Jan 22, 2021
ada821c
Get user RSVP events by user id
Jan 22, 2021
3d70fed
Check if the user has entry inside the user_event table
Jan 22, 2021
8ad0284
Create an new entry and add the event
Jan 22, 2021
af14eda
Get all entries from user_event table
Jan 22, 2021
e551b67
Un RSVP an event
Jan 22, 2021
70ae62d
RSVP an event
Jan 22, 2021
4dc7e0b
Create an entry and RSVP the event
Jan 22, 2021
6d32bf6
Unfollow an event
Jan 22, 2021
167e2e3
Follow an event
Jan 22, 2021
dbdebc7
Move to event_api
Jan 22, 2021
9ad0f7b
Rely on user_event rather than user_profile
Jan 22, 2021
cad51e7
Update event.js
Jan 22, 2021
5f2d1f3
Un RSVP
Jan 22, 2021
b651142
RSVP
Jan 22, 2021
df46807
Update event_api.js
Jan 22, 2021
c4e3946
Merge branch 'dev' into event-follow-save
jialuogao May 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ if (process.env.INSTALL === 'yes' || args[0] === 'install') {
});
}

const child_process = require('child_process');
child_process.fork('rsvp_sender');

module.exports = app;
1 change: 0 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ input::-webkit-calendar-picker-indicator {
padding-top: 10px;
z-index: 1050;
font-size: 15px;
background-color: #51a351;
color: #ffffff;
text-align: center;
border-bottom-left-radius: 20px 10px;
Expand Down
92 changes: 77 additions & 15 deletions routes/event/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,54 @@ const authService = require('../services/authorization_service');

router.get('/', function (req, res, next) {
let offset = 0;
event_db.getEventSet(offset, function (err, eventsSet) {
let uid = req.session.uid;
event_db.getEventSet(offset, function (err, events_set) {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
return;
}
user_db.getUserRoleByUid(req.session.uid, function (err, user_role) {
user_db.getUserRoleByUid(uid, (err, user_role) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
return;
}
eventsSet = eventsSet.sort(function (a, b) {
return a.event_time - b.event_time
})
let now = new Date();
now = new Date(now - (5.5 * 60 * 60 * 1000));
var centerIdx = eventsSet.length - 1;
for (var i = eventsSet.length - 1; i >= 0; i--) {
// show the event thats coming up soon
if (eventsSet[i].event_time < now) {
break;
user_db.getUserFollowedEventsByUid(uid, (err, followed_events) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
return;
}
centerIdx = i;
}
res.render('event/index', {eventsSet: eventsSet, uid: req.session.uid, all_user_role: authService.UserRole, user_role: user_role, centerIdx: centerIdx});
user_db.getUserRSVPEventsByUid(uid, (err, rsvp_events) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
return;
}
events_set = events_set.sort((event_a, event_b) => {
return event_a.event_time - event_b.event_time
})
let now = new Date();
now = new Date(now - (5.5 * 60 * 60 * 1000));
let center_idx = events_set.length - 1;
for (let i = events_set.length - 1; i >= 0; i--) {
if (events_set[i].event_time < now) {
break;
}
center_idx = i;
}
res.render('event/index', {
followed_events: JSON.parse(followed_events),
rsvp_events: JSON.parse(rsvp_events),
eventsSet: events_set,
uid: req.session.uid,
all_user_role: authService.UserRole,
user_role: user_role,
centerIdx: center_idx
});
});
});
});
});
});
Expand Down Expand Up @@ -86,4 +109,43 @@ router.get('/edit', function (req, res, next) {
});
});

router.get('/followed', function (req, res, next) {
let uid = req.query.user_id ? req.query.user_id : req.session.uid;
authService.authorizationCheck(null, req.session.uid, function(err, authorized){
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
}
else if(!authorized) {
res.redirect('/login');
} else {
user_db.getUserFollowedEventsByUid(uid, (err, followed_events) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
} else {
event_db.getEventSet((err, event_set) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Database Error'});
}
let followed_event_ids = JSON.parse(followed_events);
let followed_event_set = [];

event_set.forEach(function (event) {
if (followed_event_ids.includes(event.id)) {
followed_event_set.push(event);
}
});

res.render('event/followed', {
event_set: followed_event_set
});
});
}
});
}
});
});

module.exports = router;
98 changes: 98 additions & 0 deletions routes/event/event_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const event_db = require('../../server/event_db');
const user_db = require('../../server/user_db');
const router = express.Router();
const authService = require('../services/authorization_service');

Expand Down Expand Up @@ -106,4 +107,101 @@ router.post('/changeEventStatus', function(req, res, next){
});
});

router.post('/followEvent', function(req, res, next) {
if(!req.body.uid){
res.status(403).json({msg: 'Not Authorized'});
return;
}
user_db.hasUserEventEntry(req.body.uid, (err, has_entry) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to check entry'});
return;
}
if (has_entry) {
user_db.followEvent(req.body.uid, req.body.eid, (err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to follow event'});
return;
}
res.json({});
});
} else {
user_db.createEntryAndFollowEvent(req.body.uid, req.body.eid, (err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to create entry and follow event'});
return;
}
res.json({});
})
}
});
});

router.post('/unfollowEvent', function(req, res, next) {
if(!req.body.uid){
res.status(403).json({msg: 'Not Authorized'});
return;
}
user_db.unfollowEvent(req.body.uid, req.body.eid, ((err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to unfollow event'});
return;
}
res.json({});
}))
});

router.post('/rsvpEvent', function (req, res, next) {
if(!req.body.uid){
res.status(403).json({msg: 'Not Authorized'});
return;
}
user_db.hasUserEventEntry(req.body.uid, (err, has_entry) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to check entry'});
return;
}
if (has_entry) {
user_db.rsvpEvent(req.body.uid, req.body.eid, (err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to RSVP event'});
return;
}

res.json({});
});
} else {
user_db.createEntryAndRSVPEvent(req.body.uid, req.body.eid, (err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to create entry and RSVP event'});
return;
}
res.json({});
});
}
});
});

router.post('/unrsvpEvent', function(req, res, next) {
if(!req.body.uid){
res.status(403).json({msg: 'Not Authorized'});
return;
}
user_db.unrsvpEvent(req.body.uid, req.body.eid, ((err) => {
if (err) {
console.log(err);
res.status(400).json({msg: 'Failed to unfollow event'});
return;
}
res.json({});
}))
});

module.exports = router;
56 changes: 56 additions & 0 deletions rsvp_sender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const nodemailer = require('nodemailer');
const user_db = require('./server/user_db');
const event_db = require('./server/event_db');


setInterval(() => {
user_db.getAllEntriesFromUserEvent((err, user_event_entries) => {
if (err) {
console.log("Failed to get all entries from user event");
return;
}
user_event_entries.rows.forEach((row) => {
const uid = row.uid;
const rsvp_events = JSON.parse(row.rsvp_events);
rsvp_events.forEach((rsvp_event) => {
event_db.getEventById(rsvp_event, (err, event_info) => {
if (!err) {
let now = new Date();
// TODO: !!!!!!!!
if (!(now.toLocaleDateString() === event_info.event_time.toLocaleDateString())) {
user_db.getUserEmailById(uid, (err, user_email) => {
if (!err) {
let mail_options = {
from: process.env.EMAILUSER,
to: user_email.email,
subject: 'Event Reminder: ' + event_info.title,
text: event_info.description,
};
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAILUSER,
pass: process.env.EMAILPASS,
}
});
transporter.sendMail(mail_options, (err, info) => {
if (err) {
console.log(err);
} else {
user_db.unrsvpEvent(uid, event_info.id, (err) => {
if (err) {
console.log(err);
}
console.log('Email sent: ' + info.response);
});
}
});
}
});
}
}
});
});
})
});
}, 1000);
Loading