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 1/2] 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 } From a264a0b1261004352d5f94df921dd215aa44f145 Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Thu, 29 Feb 2024 20:23:48 +0000 Subject: [PATCH 2/2] Lint --- pkg/api/resolver_mutation_performer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/api/resolver_mutation_performer.go b/pkg/api/resolver_mutation_performer.go index bebadd26c..e23c2a498 100644 --- a/pkg/api/resolver_mutation_performer.go +++ b/pkg/api/resolver_mutation_performer.go @@ -226,9 +226,8 @@ func (r *mutationResolver) FavoritePerformer(ctx context.Context, id uuid.UUID, performerFavorite := models.PerformerFavorite{PerformerID: id, UserID: user.ID} if favorite { return jqb.AddPerformerFavorite(performerFavorite) - } else { - return jqb.DestroyPerformerFavorite(performerFavorite) } + return jqb.DestroyPerformerFavorite(performerFavorite) }) return err == nil, err }