storj/satellite/console/consoleweb/consoleql/query.go
Yingrong Zhao 3b49d3cddf satellite: remove referral program related code
This PR removes all back-end related referral program code including the
marketing portal.

We will have a separate PR for front-end code and database migration to
drop `offers` and `usercredits` table

Change-Id: If59f952cddfe0558a7dc03a0eac7cc1081517f88
2021-02-08 13:52:50 +00:00

102 lines
2.9 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleql
import (
"github.com/graphql-go/graphql"
"github.com/zeebo/errs"
"storj.io/common/uuid"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/mailservice"
)
const (
// Query is immutable graphql request.
Query = "query"
// ProjectQuery is a query name for project.
ProjectQuery = "project"
// OwnedProjectsQuery is a query name for projects owned by an account.
OwnedProjectsQuery = "ownedProjects"
// MyProjectsQuery is a query name for projects related to account.
MyProjectsQuery = "myProjects"
// ActiveRewardQuery is a query name for current active reward offer.
ActiveRewardQuery = "activeReward"
// CreditUsageQuery is a query name for credit usage related to an user.
CreditUsageQuery = "creditUsage"
)
// rootQuery creates query for graphql populated by AccountsClient.
func rootQuery(service *console.Service, mailService *mailservice.Service, types *TypeCreator) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: Query,
Fields: graphql.Fields{
ProjectQuery: &graphql.Field{
Type: types.project,
Args: graphql.FieldConfigArgument{
FieldID: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
inputID, _ := p.Args[FieldID].(string)
id, err := uuid.FromString(inputID)
if err != nil {
return nil, err
}
project, err := service.GetProject(p.Context, id)
if err != nil {
return nil, err
}
return project, nil
},
},
OwnedProjectsQuery: &graphql.Field{
Type: types.projectsPage,
Args: graphql.FieldConfigArgument{
CursorArg: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(types.projectsCursor),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
cursor := fromMapProjectsCursor(p.Args[CursorArg].(map[string]interface{}))
page, err := service.GetUsersOwnedProjectsPage(p.Context, cursor)
return page, err
},
},
MyProjectsQuery: &graphql.Field{
Type: graphql.NewList(types.project),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
projects, err := service.GetUsersProjects(p.Context)
if err != nil {
return nil, err
}
return projects, nil
},
},
ActiveRewardQuery: &graphql.Field{
Type: types.reward,
Args: graphql.FieldConfigArgument{
FieldType: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.Int),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return nil, errs.New("endpoint deprecated")
},
},
CreditUsageQuery: &graphql.Field{
Type: types.creditUsage,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return nil, errs.New("endpoint deprecated")
},
},
},
})
}