Skip to content
Closed
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ const resolvers = {
if (!group) return new UserInputError("No group exists with that id.");
if (!group.members.includes(user.id) && group.leader != user.id)
return new Error("User is not a part of the group!");

const existingBeacon = await Beacon.findOne({ leader: user.id });
if (existingBeacon) {
return new Error("User cannot lead more than one hike at a time.");
}
const beaconDoc = new Beacon({
leader: user.id,
shortcode: nanoid(),
Expand Down Expand Up @@ -418,6 +421,10 @@ const resolvers = {
if (!beacon) return new UserInputError("No beacon exists with that shortcode.");
if (beacon.expiresAt < Date.now()) return new Error("Beacon has expired");
if (beacon.leader == user.id) return new Error("Already leading the beacon!");
const followingBeacon = await Beacon.findOne({ followers: user.id });
if (followingBeacon) {
return new Error("User cannot join more than one hike at a time.");
}
for (let i = 0; i < beacon.followers.length; i++)
if (beacon.followers[i].id === user.id) {
return new Error("Already following the beacon!");
Expand Down