2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-15 12:00:08 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-11-14 10:50:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
2018-11-21 15:51:43 +00:00
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-01-24 16:26:36 +00:00
|
|
|
// UserType is a graphql type for user
|
|
|
|
UserType = "user"
|
|
|
|
// UserInputType is a graphql type for user input
|
|
|
|
UserInputType = "userInput"
|
|
|
|
// FieldID is a field name for id
|
|
|
|
FieldID = "id"
|
|
|
|
// FieldEmail is a field name for email
|
|
|
|
FieldEmail = "email"
|
|
|
|
// FieldPassword is a field name for password
|
|
|
|
FieldPassword = "password"
|
2019-03-27 12:33:32 +00:00
|
|
|
// FieldFullName is a field name for "first name"
|
|
|
|
FieldFullName = "fullName"
|
|
|
|
// FieldShortName is a field name for "last name"
|
|
|
|
FieldShortName = "shortName"
|
2019-01-24 16:26:36 +00:00
|
|
|
// FieldCreatedAt is a field name for created at timestamp
|
|
|
|
FieldCreatedAt = "createdAt"
|
2019-07-17 21:53:14 +01:00
|
|
|
// FieldPartnerID is a field name for partnerID
|
|
|
|
FieldPartnerID = "partnerId"
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
2018-11-27 14:20:58 +00:00
|
|
|
// base graphql config for user
|
|
|
|
func baseUserConfig() graphql.ObjectConfig {
|
|
|
|
return graphql.ObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: UserType,
|
2018-11-14 10:50:15 +00:00
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.Field{
|
2018-11-14 10:50:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldEmail: &graphql.Field{
|
2018-11-14 10:50:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-03-27 12:33:32 +00:00
|
|
|
FieldFullName: &graphql.Field{
|
2018-11-14 10:50:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-03-27 12:33:32 +00:00
|
|
|
FieldShortName: &graphql.Field{
|
2018-11-14 10:50:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldCreatedAt: &graphql.Field{
|
2018-11-14 15:13:13 +00:00
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
2019-07-17 21:53:14 +01:00
|
|
|
FieldPartnerID: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-11-27 14:20:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// graphqlUser creates *graphql.Object type representation of satellite.User
|
2018-12-20 16:18:08 +00:00
|
|
|
// TODO: simplify
|
|
|
|
func graphqlUser() *graphql.Object {
|
|
|
|
return graphql.NewObject(baseUserConfig())
|
2018-11-14 10:50:15 +00:00
|
|
|
}
|
2018-11-21 15:51:43 +00:00
|
|
|
|
|
|
|
// graphqlUserInput creates graphql.InputObject type needed to register/update satellite.User
|
2019-04-04 15:56:20 +01:00
|
|
|
func graphqlUserInput() *graphql.InputObject {
|
2018-11-21 15:51:43 +00:00
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: UserInputType,
|
2018-11-21 15:51:43 +00:00
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldEmail: &graphql.InputObjectFieldConfig{
|
2018-11-21 15:51:43 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-03-27 12:33:32 +00:00
|
|
|
FieldFullName: &graphql.InputObjectFieldConfig{
|
2018-11-21 15:51:43 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-03-27 12:33:32 +00:00
|
|
|
FieldShortName: &graphql.InputObjectFieldConfig{
|
2018-11-21 15:51:43 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldPassword: &graphql.InputObjectFieldConfig{
|
2018-11-21 15:51:43 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-07-17 21:53:14 +01:00
|
|
|
FieldPartnerID: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-11-21 15:51:43 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:24:16 +00:00
|
|
|
func fromMapCreateUser(args map[string]interface{}) (user console.CreateUser) {
|
2019-01-24 16:26:36 +00:00
|
|
|
user.Email, _ = args[FieldEmail].(string)
|
2019-03-27 12:33:32 +00:00
|
|
|
user.FullName, _ = args[FieldFullName].(string)
|
|
|
|
user.ShortName, _ = args[FieldShortName].(string)
|
2019-01-24 16:26:36 +00:00
|
|
|
user.Password, _ = args[FieldPassword].(string)
|
2019-10-29 14:24:16 +00:00
|
|
|
user.PartnerID, _ = args[FieldPartnerID].(string)
|
2018-11-21 15:51:43 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-28 10:31:15 +00:00
|
|
|
|
2018-11-28 12:30:38 +00:00
|
|
|
// fillUserInfo fills satellite.UserInfo from satellite.User and input args
|
2019-01-15 13:03:24 +00:00
|
|
|
func fillUserInfo(user *console.User, args map[string]interface{}) console.UserInfo {
|
|
|
|
info := console.UserInfo{
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: user.FullName,
|
|
|
|
ShortName: user.ShortName,
|
2018-11-28 10:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for fieldName, fieldValue := range args {
|
|
|
|
value, ok := fieldValue.(string)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
switch fieldName {
|
2019-03-27 12:33:32 +00:00
|
|
|
case FieldFullName:
|
|
|
|
info.FullName = value
|
|
|
|
user.FullName = value
|
|
|
|
case FieldShortName:
|
|
|
|
info.ShortName = value
|
|
|
|
user.ShortName = value
|
2018-11-28 10:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return info
|
|
|
|
}
|