diff --git a/server/controller/community.ts b/server/controller/community.ts index 2958fa0..ac8e924 100644 --- a/server/controller/community.ts +++ b/server/controller/community.ts @@ -9,6 +9,13 @@ import { sortQuestionsByNewest } from '../models/application'; const communityController = (socket: FakeSOSocket) => { const router: Router = express.Router(); + /** + * Returns all the communities from the Database. + * @param req The Request object that contains the communities. + * @param res The HTTP response object used to send back the filtered list of questions. + * + * @returns A Promise that resolves to void. + */ const getCommunityNames = async (req: Request, res: Response): Promise => { try { const communities = await CommunityModel.find({}); @@ -18,6 +25,13 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Finds a Community by Name. + * @param name The Request object with the community name. + * @returns The HTTP response object used to send back the filtered list of questions. + * + * @returns A Promise that resolves to Community or null if not found. + */ const getCommunityByName = async (name: string): Promise => { try { const community = await CommunityModel.findOne({ name }).populate('questions'); @@ -36,6 +50,14 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Gets the questionss of a Commubnity. + * + * @param req The Request object that contains the Community. + * @param res The HTTP response object used to send back the filtered list of questions. + * + * @returns A Promise that resolves to a void. + */ const getCommunityQuestions = async (req: Request, res: Response): Promise => { const { community } = req.params; @@ -59,6 +81,13 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Adds the username to the Community. + * @param req The Request object that contains a username and a community name. + * @param res The HTTP response object used to add the username to the community. + * + * @returns A Promise that resolves to a void. + */ const addUserToCommunity = async (req: Request, res: Response): Promise => { const { username, community } = req.body; @@ -116,6 +145,13 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Finds the relavant communities based on the tags. + * @param req The Request object that contains tags. + * @param res The HTTP response object used to find the relevant communties based on the tags. + * + * @returns A Promise that resolves to a void. + */ const getRelevantCommunities = async (req: Request, res: Response): Promise => { const { tags } = req.query; @@ -141,6 +177,12 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Updates the Questions in a Community. + * @param req The Request object that updates the Community with a new Question. + * @param res The HTTP response object used to add questions to communities. + * @returns A Promise that resolves to a void. + */ const updateCommunityQuestions = async (req: Request, res: Response): Promise => { const { communityName } = req.params; const { questionId } = req.body; @@ -192,6 +234,13 @@ const communityController = (socket: FakeSOSocket) => { } }; + /** + * Finds all the members in a community. + * @param req The Request object containinng the community name. + * @param res The HTTP response object used to find the members of a community. + * + * @returns A Promise that resolves to a void. + */ const getCommunityMembers = async (req: Request, res: Response): Promise => { const { community } = req.params; console.log(`Received request to get members of community: ${community}`); diff --git a/server/controller/question.ts b/server/controller/question.ts index dd9b1b8..da8d538 100644 --- a/server/controller/question.ts +++ b/server/controller/question.ts @@ -253,6 +253,13 @@ const questionController = (socket: FakeSOSocket) => { } }; + /** + * Handles deleting a question from the database. + * + * @param req The FindQuestionByIdRequest object containing the question ID . + * @param res The HTTP response object used to send back the result of the operation. + * + */ const removeQuestion = async (req: FindQuestionByIdRequest, res: Response): Promise => { try { const { qid } = req.params; diff --git a/server/controller/tag.ts b/server/controller/tag.ts index 7f7e0a3..fb28b7f 100644 --- a/server/controller/tag.ts +++ b/server/controller/tag.ts @@ -57,7 +57,7 @@ const tagController = () => { }; /** - * MAKE TESTS*************** + * Finds all the tags. * @param req The Request object containing the tag name in the URL parameters. * @param res The HTTP response object used to send back the result of the operation. */ diff --git a/server/controller/user.ts b/server/controller/user.ts index cbbd722..925e185 100644 --- a/server/controller/user.ts +++ b/server/controller/user.ts @@ -7,6 +7,10 @@ const userController = (socket: FakeSOSocket) => { /** * Adds a new user to the database. + * @param req The Request object that contains the all the information of users. + * @param res The HTTP response object used to add users. + * + * @returns A Promise that resolves to void. */ const addUser = async (req: Request, res: Response): Promise => { try { @@ -29,6 +33,10 @@ const userController = (socket: FakeSOSocket) => { /** * Updates the tags for a given user. + * @param req The Request object that contains the username and tags of a user. + * @param res The HTTP response object used to update the user tag list. + * + * @returns A Promise that resolves to void. */ const updateUserTags = async (req: Request, res: Response): Promise => { try { @@ -55,7 +63,11 @@ const userController = (socket: FakeSOSocket) => { }; /** - * Updates the community for a given user. + * Updates the users community. + * @param req The Request object that contains the community name and username. + * @param res The HTTP response object used to update the users community. + * + * @returns A Promise that resolves to void. */ const updateUserCommunity = async (req: Request, res: Response): Promise => { try { @@ -81,6 +93,10 @@ const userController = (socket: FakeSOSocket) => { /** * Retrieves user data based on the provided username. + * @param req The Request object that a username. + * @param res The HTTP response object used to retreive user data. + * + * @returns A Promise that resolves to void. */ const getUser = async (req: Request, res: Response): Promise => { try { @@ -110,6 +126,11 @@ const userController = (socket: FakeSOSocket) => { router.put('/updateCommunity', updateUserCommunity); router.get('/getUser', getUser); + /** + * Returns all the users. + * @param req The Request object that contains all the users. + * @param res The HTTP response object used to get all the users. + */ router.get('/getListOfAllUsers', async (req: Request, res: Response) => { try { const users = await UserModel.find(); @@ -124,6 +145,11 @@ const userController = (socket: FakeSOSocket) => { } }); + /** + * Increases a users status to moderator. + * @param req The Request object that contains the username. + * @param res The HTTP response object used to incerase user status. + */ router.put('/increaseUserStatus', async (req: Request, res: Response) => { try { const { username } = req.body;