Skip to content

Commit

Permalink
group subscription added
Browse files Browse the repository at this point in the history
  • Loading branch information
Shock@5678 committed Aug 21, 2024
1 parent 1592718 commit a020198
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ const resolvers = {
},

oAuth: async (_parent, { userInput }) => {
console.log("coming here");

console.log('coming here');
const { name, email } = userInput;
let user = await User.findOne({ email });

Expand All @@ -209,12 +210,13 @@ const resolvers = {
},

login: async (_parent, { id, credentials }) => {
console.log(credentials);

console.log(credentials)

if (!id && !credentials) return new UserInputError("One of ID and credentials required");

const { email, password } = credentials || {}; // unpack if available
console.log(email, password);
console.log(email, password)
const user = id ? await User.findById(id) : await User.findOne({ email });

if (!user) return new Error("User not found.");
Expand Down Expand Up @@ -707,6 +709,44 @@ const resolvers = {
}
),
},
groupUpdate: {
subscribe: withFilter(
(_, __, { pubsub }) => pubsub.asyncIterator(["GROUP_UPDATE"]),
(payload, variables, { user }) => {
const { groupID, groupMembers, groupLeader, groupUpdate } = payload;

let { newBeacon, groupId, deletedBeacon, updatedBeacon, newUser } = groupUpdate;
if (newBeacon != null) {
if (newBeacon.leader._id == user.id) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.newBeacon = parseBeaconObject(newBeacon);
} else if (deletedBeacon != null) {
if (deletedBeacon.leader.toString() === user._id.toString()) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.deletedBeacon = parseBeaconObject(deletedBeacon);
} else if (updatedBeacon != null) {
if (updatedBeacon.leader._id == user.id) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.updatedBeacon = parseBeaconObject(updatedBeacon);
}
if (!variables.groupIds.includes(groupID)) {
return false;
}
// checking if user is part of group or not
const isGroupLeader = groupLeader === user.id.toString();
const isGroupMember = groupMembers.includes(user.id);

let istrue = isGroupLeader || isGroupMember;
return istrue && variables.groupIds.includes(groupId);
}
),
},
},
}),
};
Expand Down

0 comments on commit a020198

Please sign in to comment.