Skip to content

Commit

Permalink
mods cant approve their own request
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonnorsworthy committed Sep 21, 2024
1 parent 931bb86 commit 2beab8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion controllers/suggestion.controller .ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {

convertSuggestionIntoQuest: async (request: Request, response: Response) => {
try {
const { userId } = (request as AuthenticatedRequest).tokenData;
const { userId, role } = (request as AuthenticatedRequest).tokenData;
const { suggestionId } = request.params;
let { title, description, objectives, categoryId, image_url } = request.body;

Expand All @@ -62,6 +62,10 @@ export default {
return response.status(404).send('Suggestion not found');
}

if (role !== "admin" || suggestion.user_id !== userId) {
return response.status(403).send('You are not allowed to convert this suggestion into a quest');
}

const newQuest = await questService.createQuest(title, description, objectives, categoryId, suggestion.user_id, image_url);
await suggestionService.deleteSuggestion(Number(suggestionId), userId);

Expand Down
4 changes: 1 addition & 3 deletions routes/suggestion.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ suggestionRouter.delete(
validateParams(suggestionSchema.suggestionId),
suggestionController.deleteSuggestion
);

// admin routes
suggestionRouter.post(
'/:suggestionId/quest',
isAdmin,
isModerator,
validateParams(suggestionSchema.suggestionId),
validateBody(suggestionSchema.convertSuggestionIntoQuestBody),
suggestionController.convertSuggestionIntoQuest
Expand Down

0 comments on commit 2beab8b

Please sign in to comment.