Skip to content

Commit

Permalink
rest of merge
Browse files Browse the repository at this point in the history
  • Loading branch information
joneslizzie committed Nov 26, 2024
1 parent a45fc13 commit 88f77c2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
6 changes: 2 additions & 4 deletions server/controller/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import express, { Request, Response, Router } from 'express';
import CommunityModel from '../models/communities';
import { Community, FakeSOSocket } from '../types';
import TagModel from '../models/tags';
import { FakeSOSocket, Question } from '../types';
import QuestionModel from '../models/questions';

const communityController = (socket: FakeSOSocket) => {
Expand Down Expand Up @@ -79,7 +78,6 @@ const communityController = (socket: FakeSOSocket) => {
name: comm.name,
users: comm.users.filter(user => user !== username),
tags: comm.tags,
questions: comm.questions,
});
});
res.status(200).json({ message: 'User removed from all communities successfully' });
Expand All @@ -94,7 +92,6 @@ const communityController = (socket: FakeSOSocket) => {
name: comm.name,
users: comm.users.filter(user => user !== username),
tags: comm.tags,
questions: comm.questions,
});
});

Expand All @@ -112,7 +109,6 @@ const communityController = (socket: FakeSOSocket) => {
name: newCommunity.name,
tags: newCommunity.tags,
users: newCommunity.users,
questions: newCommunity.questions,
});
console.log(`Added user: ${username} to new community: ${newCommunity}`);
res.status(200).json('successfully added to the community users list');
Expand Down Expand Up @@ -204,6 +200,8 @@ const communityController = (socket: FakeSOSocket) => {
router.get('/getCommunityQuestions/:community', getCommunityQuestions);
router.get('/getCommunityMembers/:community', getCommunityMembers);
router.get('/getRelevantCommunities', getRelevantCommunities);
router.patch('/addUserToCommunity/:communityName', addUserToCommunity);
router.patch('/updateCommunityQuestions/:communityName', updateCommunityQuestions);

return router;
};
Expand Down
27 changes: 0 additions & 27 deletions server/models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,30 +647,3 @@ export const getTagCountMap = async (): Promise<Map<string, number> | null | { e
return { error: 'Error when construction tag map' };
}
};

// ADD COMMENT LATER
export const usersNewCommunity = async (
username: string,
communityName: string,
): Promise<Community> => {
try {
console.log(`Removing user ${username} from all communities`);
await CommunityModel.updateMany({ users: username }, { $pull: { users: username } });

console.log(`Adding user ${username} to the new community`);
const updatedCommunity = await CommunityModel.findOneAndUpdate(
{ name: communityName },
{ $addToSet: { users: username } },
{ new: true },
);

if (!updatedCommunity) {
throw new Error('Failed to update community');
}
// await UserModel.findOneAndUpdate({ username }, { community: communityName }, { new: true });
console.log(`User ${username} successfully added to the community`);
return updatedCommunity;
} catch (error) {
throw new Error('Failed to update user community');
}
};
1 change: 0 additions & 1 deletion server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export interface CommunityUpdatePayload {
name: string;
tags: string[];
users: string[];
questions: Question[];
}

// ADD COMMENT
Expand Down

0 comments on commit 88f77c2

Please sign in to comment.