From fa50fa51172f582636da774fda84876d3688879d Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Thu, 29 Feb 2024 11:07:46 +0000 Subject: [PATCH] Fix nil error when favoriting non-existant performer --- pkg/api/resolver_mutation_performer.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/api/resolver_mutation_performer.go b/pkg/api/resolver_mutation_performer.go index f76730307..bebadd26c 100644 --- a/pkg/api/resolver_mutation_performer.go +++ b/pkg/api/resolver_mutation_performer.go @@ -215,16 +215,20 @@ func (r *mutationResolver) FavoritePerformer(ctx context.Context, id uuid.UUID, if err != nil { return err } + if performer == nil { + return fmt.Errorf("performer not found") + } + if performer.Deleted { return fmt.Errorf("performer is deleted, unable to make favorite") } + performerFavorite := models.PerformerFavorite{PerformerID: id, UserID: user.ID} if favorite { - pf := models.PerformerFavorite{PerformerID: id, UserID: user.ID} - err := jqb.AddPerformerFavorite(pf) - return err + return jqb.AddPerformerFavorite(performerFavorite) + } else { + return jqb.DestroyPerformerFavorite(performerFavorite) } - return jqb.DestroyPerformerFavorite(models.PerformerFavorite{PerformerID: id, UserID: user.ID}) }) return err == nil, err }