Skip to content

Commit

Permalink
refactor: reorder checks before allowing edit of tt metadata
Browse files Browse the repository at this point in the history
check if requester owns the tt before logical checks
  • Loading branch information
majimearun committed Dec 29, 2023
1 parent 70aa163 commit 91ae517
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/src/controllers/timetable/editTimetableMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const editTimetableMetadata = async (req: Request, res: Response) => {
return res.status(404).json({ message: "timetable not found" });
}

if (timetable.authorId !== author.id) {
return res.status(403).json({ message: "user does not own timetable" });
}

if (
timetable.draft &&
timetable.sections.length === 0 &&
Expand All @@ -92,10 +96,6 @@ export const editTimetableMetadata = async (req: Request, res: Response) => {
});
}

if (timetable.authorId !== author.id) {
return res.status(403).json({ message: "user does not own timetable" });
}

try {
await timetableRepository
.createQueryBuilder("timetable")
Expand Down

0 comments on commit 91ae517

Please sign in to comment.