Skip to content

Commit

Permalink
finished comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joneslizzie committed Nov 29, 2024
1 parent 31c6935 commit e04b690
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
49 changes: 49 additions & 0 deletions server/controller/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
try {
const communities = await CommunityModel.find({});
Expand All @@ -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<Community | null> => {
try {
const community = await CommunityModel.findOne({ name }).populate('questions');
Expand All @@ -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<void> => {
const { community } = req.params;

Expand All @@ -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<void> => {
const { username, community } = req.body;

Expand Down Expand Up @@ -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<void> => {
const { tags } = req.query;

Expand All @@ -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<void> => {
const { communityName } = req.params;
const { questionId } = req.body;
Expand Down Expand Up @@ -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<void> => {
const { community } = req.params;
console.log(`Received request to get members of community: ${community}`);
Expand Down
7 changes: 7 additions & 0 deletions server/controller/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
try {
const { qid } = req.params;
Expand Down
2 changes: 1 addition & 1 deletion server/controller/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
28 changes: 27 additions & 1 deletion server/controller/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
try {
Expand All @@ -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<void> => {
try {
Expand All @@ -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<void> => {
try {
Expand All @@ -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<void> => {
try {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit e04b690

Please sign in to comment.