Skip to content

Commit

Permalink
Improved validation in UpdateEpisodeOrderMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Nov 4, 2024
1 parent 1fa7d17 commit 6aca9ad
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions backend/event/mutations/UpdateEpisodeOrderMutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@ class Arguments:

@classmethod
def mutate(cls, root: None, info: ResolveInfo, episode_ids: list[str]):
source = Source.objects.filter(episode__in=episode_ids).distinct()
if len(episode_ids) == 0:
error=LettercraftErrorType(
field="episode_ids",
messages=["No episode IDs provided."]
)
return cls(ok=False, errors=[error]) # type: ignore

if source.count() > 1:
corresponding_sources = Source.objects.filter(episode__in=episode_ids)
if corresponding_sources.count() != len(episode_ids):
error = LettercraftErrorType(
field="episode_ids",
messages=["Multiple sources found for given episode IDs."],
messages=["Not every episode has a corresponding source."]
)
return cls(ok=False, errors=[error]) # type: ignore
return cls(ok=False, errors=[error]) # type: ignore

source = source.first()
distinct_sources = corresponding_sources.distinct()
if distinct_sources.count() > 1:
error = LettercraftErrorType(
field="episode_ids",
messages=["The provided episode IDs belong to more than one source."],
)
return cls(ok=False, errors=[error]) # type: ignore

source = distinct_sources.first()
if not source:
error = LettercraftErrorType(
field="episode_ids",
Expand Down

0 comments on commit 6aca9ad

Please sign in to comment.