/
insight_product.resolvers.go
89 lines (73 loc) · 2.86 KB
/
insight_product.resolvers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.44
import (
"context"
"github.com/google/uuid"
"github.com/navikt/nada-backend/pkg/auth"
"github.com/navikt/nada-backend/pkg/graph/generated"
"github.com/navikt/nada-backend/pkg/graph/models"
)
// ProductAreaID is the resolver for the productAreaID field.
func (r *insightProductResolver) ProductAreaID(ctx context.Context, obj *models.InsightProduct) (*string, error) {
if teamID := ptrToString(obj.TeamID); teamID != "" {
team, err := r.teamkatalogen.GetTeam(ctx, teamID)
if err != nil {
return nil, err
}
return &team.ProductAreaID, nil
}
return nil, nil
}
// CreateInsightProduct is the resolver for the createInsightProduct field.
func (r *mutationResolver) CreateInsightProduct(ctx context.Context, input models.NewInsightProduct) (*models.InsightProduct, error) {
return r.repo.CreateInsightProduct(ctx, auth.GetUser(ctx).Email, input)
}
// UpdateInsightProductMetadata is the resolver for the updateInsightProductMetadata field.
func (r *mutationResolver) UpdateInsightProductMetadata(ctx context.Context, id uuid.UUID, name string, description string, typeArg string, link string, keywords []string, teamkatalogenURL *string, productAreaID *string, teamID *string, group string) (*models.InsightProduct, error) {
existing, err := r.repo.GetInsightProduct(ctx, id)
if err != nil {
return nil, err
}
existing.Creator = ""
/*
user := auth.GetUser(ctx)
if !user.GoogleGroups.Contains(existing.Group) {
return nil, ErrUnauthorized
}
*/
insightProduct, err := r.repo.UpdateInsightProductMetadata(ctx, id, name, description, keywords, teamkatalogenURL,
productAreaID, teamID, typeArg, link)
if err != nil {
return nil, err
}
return insightProduct, nil
}
// DeleteInsightProduct is the resolver for the deleteInsightProduct field.
func (r *mutationResolver) DeleteInsightProduct(ctx context.Context, id uuid.UUID) (bool, error) {
s, err := r.repo.GetInsightProduct(ctx, id)
if err != nil {
return false, err
}
s.Creator = ""
/*
user := auth.GetUser(ctx)
if !user.GoogleGroups.Contains(s.Group) {
return false, ErrUnauthorized
}
*/
if err = r.repo.DeleteInsightProduct(ctx, id); err != nil {
return false, err
}
return true, nil
}
// InsightProduct is the resolver for the InsightProduct field.
func (r *queryResolver) InsightProduct(ctx context.Context, id uuid.UUID) (*models.InsightProduct, error) {
return r.repo.GetInsightProduct(ctx, id)
}
// InsightProduct returns generated.InsightProductResolver implementation.
func (r *Resolver) InsightProduct() generated.InsightProductResolver {
return &insightProductResolver{r}
}
type insightProductResolver struct{ *Resolver }