diff --git a/server/controller/community.ts b/server/controller/community.ts index a8301e5..e77832d 100644 --- a/server/controller/community.ts +++ b/server/controller/community.ts @@ -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) => { @@ -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' }); @@ -94,7 +92,6 @@ const communityController = (socket: FakeSOSocket) => { name: comm.name, users: comm.users.filter(user => user !== username), tags: comm.tags, - questions: comm.questions, }); }); @@ -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'); @@ -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; }; diff --git a/server/models/application.ts b/server/models/application.ts index 0b4db98..543f789 100644 --- a/server/models/application.ts +++ b/server/models/application.ts @@ -647,30 +647,3 @@ export const getTagCountMap = async (): Promise | null | { e return { error: 'Error when construction tag map' }; } }; - -// ADD COMMENT LATER -export const usersNewCommunity = async ( - username: string, - communityName: string, -): Promise => { - 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'); - } -}; diff --git a/server/types.ts b/server/types.ts index 5bc78b1..00a995e 100644 --- a/server/types.ts +++ b/server/types.ts @@ -226,7 +226,6 @@ export interface CommunityUpdatePayload { name: string; tags: string[]; users: string[]; - questions: Question[]; } // ADD COMMENT