Skip to content

Commit da16d89

Browse files
committed
Block Users from subscribing to an event if not eligible
1 parent f48fc03 commit da16d89

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

src/controllers/Events/createEvent.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports.createEvent = async (req, res) => {
3535
description: req.body.description,
3636
host: req.body.host,
3737
status: req.body.status,
38+
eligibleProfiles: req.body.eligibleProfiles,
3839
date: req.body.date,
3940
ownerId: req.user.id,
4041
}
@@ -55,6 +56,7 @@ module.exports.createEvent = async (req, res) => {
5556
host: event.host,
5657
eventImage: event.eventImage,
5758
status: event.status,
59+
eligibleProfiles: event.eligibleProfiles,
5860
date: event.date,
5961
});
6062

src/controllers/Events/rsvpEvent.js

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ module.exports.rsvpEvent = async (req, res) => {
4545
return res.status(400).send({ msg: 'Current user not found' });
4646
}
4747

48+
const eligible = event.eligibleProfiles.includes(user.status) || user.id === event.ownerId;
49+
50+
51+
if (!eligible) {
52+
return res.status(400).send({ msg: 'You are not eligilbe to subscribe to this event.' });
53+
}
54+
4855
const alreadySub = await user.hasEvent(event);
4956

5057
if (alreadySub) return res.status(400).send({ msg: 'You are already subscribed.' });

src/controllers/User/Account/signup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports.signup = async (req, res) => {
9191
profilePicture: "https://fairfield-programming.herokuapp.com/duck/10001000005000043/",
9292
biography: "This user hasn't set a biography yet...",
9393
confirmed_email: false,
94-
status: "",
94+
status: req.body.userStatus,
9595
})
9696

9797
// generate token

src/models/Event.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = (sequelize, DataTypes) => {
66
host: DataTypes.STRING,
77
eventImage: DataTypes.TEXT,
88
status: DataTypes.STRING,
9+
eligibleProfiles: [DataTypes.STRING],
910
date: DataTypes.DATE,
1011
ownerId: DataTypes.INTEGER,
1112
});

0 commit comments

Comments
 (0)