2018-11-26 10:47:23 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satelliteql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"storj.io/storj/pkg/satellite"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
projectType = "project"
|
|
|
|
projectInputType = "projectInput"
|
|
|
|
|
2018-11-28 16:20:23 +00:00
|
|
|
fieldOwnerName = "ownerName"
|
2018-12-06 15:19:47 +00:00
|
|
|
fieldCompanyName = "companyName"
|
2018-11-26 10:47:23 +00:00
|
|
|
fieldDescription = "description"
|
|
|
|
// Indicates if user accepted Terms & Conditions during project creation
|
|
|
|
// Used in input model
|
|
|
|
fieldIsTermsAccepted = "isTermsAccepted"
|
2018-12-10 11:38:42 +00:00
|
|
|
fieldMembers = "members"
|
2018-11-26 10:47:23 +00:00
|
|
|
)
|
|
|
|
|
2018-11-28 16:20:23 +00:00
|
|
|
// graphqlProject creates *graphql.Object type representation of satellite.ProjectInfo
|
2018-12-10 11:38:42 +00:00
|
|
|
func graphqlProject(service *satellite.Service, types Types) *graphql.Object {
|
2018-11-26 10:47:23 +00:00
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: projectType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
fieldID: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-12-06 15:19:47 +00:00
|
|
|
fieldName: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-12-06 15:19:47 +00:00
|
|
|
fieldCompanyName: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
fieldDescription: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-11-28 16:20:23 +00:00
|
|
|
fieldIsTermsAccepted: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
fieldCreatedAt: &graphql.Field{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
2018-12-06 15:19:47 +00:00
|
|
|
fieldOwnerName: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2018-12-10 17:32:15 +00:00
|
|
|
// TODO: return owner (user) instead of ownerName
|
2018-12-06 15:19:47 +00:00
|
|
|
project, _ := p.Source.(satellite.Project)
|
|
|
|
if project.OwnerID == nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := service.GetUser(p.Context, *project.OwnerID)
|
|
|
|
if err != nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return user.FirstName + " " + user.LastName, nil
|
|
|
|
},
|
|
|
|
},
|
2018-12-10 11:38:42 +00:00
|
|
|
fieldMembers: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.ProjectMember()),
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
project, _ := p.Source.(*satellite.Project)
|
|
|
|
|
|
|
|
members, err := service.GetProjectMembers(p.Context, project.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var users []projectMember
|
|
|
|
for _, member := range members {
|
|
|
|
user, err := service.GetUser(p.Context, member.MemberID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
users = append(users, projectMember{
|
|
|
|
User: user,
|
|
|
|
JoinedAt: member.CreatedAt,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return users, nil
|
|
|
|
},
|
|
|
|
},
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:20:23 +00:00
|
|
|
// graphqlProjectInput creates graphql.InputObject type needed to create/update satellite.Project
|
2018-11-26 10:47:23 +00:00
|
|
|
func graphqlProjectInput() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: projectInputType,
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
|
|
|
fieldName: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-12-06 15:19:47 +00:00
|
|
|
fieldCompanyName: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-11-26 10:47:23 +00:00
|
|
|
fieldDescription: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
fieldIsTermsAccepted: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.Boolean,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// fromMapProjectInfo creates satellite.ProjectInfo from input args
|
|
|
|
func fromMapProjectInfo(args map[string]interface{}) (project satellite.ProjectInfo) {
|
|
|
|
project.Name, _ = args[fieldName].(string)
|
|
|
|
project.Description, _ = args[fieldDescription].(string)
|
|
|
|
project.IsTermsAccepted, _ = args[fieldIsTermsAccepted].(bool)
|
2018-12-06 15:19:47 +00:00
|
|
|
project.CompanyName, _ = args[fieldCompanyName].(string)
|
2018-11-26 10:47:23 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|