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 (
|
2020-08-11 15:50:01 +01:00
|
|
|
// ProjectMemberType is a graphql type name for project member.
|
2019-01-24 16:26:36 +00:00
|
|
|
ProjectMemberType = "projectMember"
|
2023-06-08 04:30:01 +01:00
|
|
|
// ProjectInvitationType is a graphql type name for project member invitation.
|
|
|
|
ProjectInvitationType = "projectInvitation"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldJoinedAt is a field name for joined at timestamp.
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldJoinedAt = "joinedAt"
|
2018-12-10 11:38:42 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01: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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-08 04:30:01 +01:00
|
|
|
// graphqlProjectInvitation creates projectInvitation type.
|
|
|
|
func graphqlProjectInvitation() *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: ProjectInvitationType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldEmail: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
FieldCreatedAt: &graphql.Field{
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-08 04:30:01 +01:00
|
|
|
func graphqlProjectMembersAndInvitationsPage(types *TypeCreator) *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
2023-06-08 09:49:53 +01:00
|
|
|
Name: ProjectMembersAndInvitationsPageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldProjectMembers: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.projectMember),
|
|
|
|
},
|
|
|
|
FieldProjectInvitations: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.projectInvitation),
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
2023-06-08 04:30:01 +01:00
|
|
|
},
|
2023-06-08 09:49:53 +01:00
|
|
|
})
|
2023-06-08 04:30:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// projectMember encapsulates User and joinedAt.
|
2018-12-10 11:38:42 +00:00
|
|
|
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 {
|
2023-06-08 04:30:01 +01:00
|
|
|
ProjectMembers []projectMember
|
|
|
|
ProjectInvitations []console.ProjectInvitation
|
2019-08-12 11:22:32 +01:00
|
|
|
|
|
|
|
Search string
|
|
|
|
Limit uint
|
|
|
|
Order int
|
|
|
|
OrderDirection int
|
|
|
|
Offset uint64
|
|
|
|
|
|
|
|
PageCount uint
|
|
|
|
CurrentPage uint
|
|
|
|
TotalCount uint64
|
|
|
|
}
|