Skip to content

Commit

Permalink
Merge pull request #95 from crux-bphc/add-warning-check-for-publishing
Browse files Browse the repository at this point in the history
Check if warnings exist before publishing a draft tt
  • Loading branch information
majimearun authored Dec 29, 2023
2 parents 84c777e + 91ae517 commit 4d8b970
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 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 @@ -83,8 +87,13 @@ export const editTimetableMetadata = async (req: Request, res: Response) => {
});
}

if (timetable.authorId !== author.id) {
return res.status(403).json({ message: "user does not own timetable" });
if (
timetable.warnings.length > 0 &&
(isDraft === false || isPrivate === false)
) {
return res.status(400).json({
message: "cannot publish timetable with warnings",
});
}

try {
Expand Down

0 comments on commit 4d8b970

Please sign in to comment.