2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-10 11:38:42 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-12-10 11:38:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2018-12-10 11:38:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-01-24 16:26:36 +00:00
|
|
|
// ProjectMemberType is a graphql type name for project member
|
|
|
|
ProjectMemberType = "projectMember"
|
|
|
|
// FieldJoinedAt is a field name for joined at timestamp
|
|
|
|
FieldJoinedAt = "joinedAt"
|
2018-12-10 11:38:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// graphqlProjectMember creates projectMember type
|
2019-04-04 15:56:20 +01:00
|
|
|
func graphqlProjectMember(service *console.Service, types *TypeCreator) *graphql.Object {
|
2018-12-10 11:38:42 +00:00
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: ProjectMemberType,
|
2018-12-10 11:38:42 +00:00
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
UserType: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.user,
|
2018-12-10 11:38:42 +00:00
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
member, _ := p.Source.(projectMember)
|
|
|
|
// company sub query expects pointer
|
|
|
|
return member.User, nil
|
|
|
|
},
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldJoinedAt: &graphql.Field{
|
2018-12-10 11:38:42 +00:00
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-12 11:22:32 +01:00
|
|
|
func graphqlProjectMembersCursor() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: ProjectMembersCursorInputType,
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
|
|
|
SearchArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
LimitArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
PageArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
OrderArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
OrderDirectionArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func graphqlProjectMembersPage(types *TypeCreator) *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: ProjectMembersPageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldProjectMembers: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.projectMember),
|
|
|
|
},
|
|
|
|
SearchArg: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
LimitArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OrderArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OrderDirectionArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OffsetArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldPageCount: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldCurrentPage: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldTotalCount: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-10 11:38:42 +00:00
|
|
|
// projectMember encapsulates User and joinedAt
|
|
|
|
type projectMember struct {
|
2019-01-15 13:03:24 +00:00
|
|
|
User *console.User
|
2018-12-10 11:38:42 +00:00
|
|
|
JoinedAt time.Time
|
|
|
|
}
|
2019-08-12 11:22:32 +01:00
|
|
|
|
|
|
|
type projectMembersPage struct {
|
|
|
|
ProjectMembers []projectMember
|
|
|
|
|
|
|
|
Search string
|
|
|
|
Limit uint
|
|
|
|
Order int
|
|
|
|
OrderDirection int
|
|
|
|
Offset uint64
|
|
|
|
|
|
|
|
PageCount uint
|
|
|
|
CurrentPage uint
|
|
|
|
TotalCount uint64
|
|
|
|
}
|