MCPcopy Create free account
hub / github.com/async-labs/async / removeTeamMember

Method removeTeamMember

api/server/models/User.ts:980–1064  ·  view source on GitHub ↗
({ removedUserEmail, teamId })

Source from the content-addressed store, hash-verified

978
979 // test
980 public static async removeTeamMember({ removedUserEmail, teamId }) {
981 if (!removedUserEmail || !teamId) {
982 throw new Error('Bad data');
983 }
984
985 const teamMember = await this.findOne({ email: removedUserEmail }).setOptions({
986 lean: true,
987 });
988
989 // Team Leader
990 await this.updateOne(
991 { 'teamsForTeamLeader.teamId': teamId },
992 {
993 $pull: { 'teamsForTeamLeader.$.idsOfTeamMembers': teamMember._id.toString() },
994 $addToSet: {
995 'teamsForTeamLeader.$.removedTeamMembers': {
996 email: removedUserEmail,
997 removalDate: new Date(),
998 userName: teamMember.userName,
999 userAvatarUrl: teamMember.userAvatarUrl,
1000 userId: teamMember._id.toString(),
1001 },
1002 },
1003 $inc: {
1004 numberOfUniqueActiveTeamMembers: -1,
1005 },
1006 },
1007 { runValidators: true },
1008 );
1009
1010 const teamLeader = await this.findOne({ 'teamsForTeamLeader.teamId': teamId }).setOptions({
1011 lean: true,
1012 });
1013
1014 if (teamLeader.isSubscriptionActiveForAccount) {
1015 const subscription = await retrieveSubscription(teamLeader.stripeSubscription.id);
1016
1017 await updateSubscription(teamLeader.stripeSubscription.id, {
1018 items: [
1019 {
1020 id: subscription.items.data[0].id,
1021 quantity: teamLeader.numberOfUniqueActiveTeamMembers,
1022 },
1023 ],
1024 });
1025 }
1026
1027 // Team Member
1028 // need fix, update defaultTeamId
1029 await this.updateOne(
1030 { email: removedUserEmail, 'teamsForTeamMember.teamId': teamId },
1031 { $set: { 'teamsForTeamMember.$.status': 'removed' } },
1032 { $pull: { 'onlineStatusByTeam.$.teamId': teamId } },
1033 );
1034
1035 const team = teamLeader.teamsForTeamLeader.find((team) => {
1036 return team.teamId === teamId;
1037 });

Callers

nothing calls this directly

Calls 4

retrieveSubscriptionFunction · 0.90
updateSubscriptionFunction · 0.90
getEmailTemplateFunction · 0.85
sendEmailFunction · 0.85

Tested by

no test coverage detected