GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package mutations
import ( "context"
"git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/character" "git.aiterp.net/rpdata/api/model/log" )
// AddCharacterNickInput is args for the addCharacterNick mutation
type AddCharacterNickInput struct { ID string Nick string }
// AddCharacterNick resolves the addCharacterNick mutation
func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ Input *AddCharacterNickInput }) (*types.CharacterResolver, error) { input := args.Input
token := auth.TokenFromContext(ctx) if !token.Permitted("member") { return nil, ErrUnauthorized }
character, err := character.FindID(input.ID) if err != nil { return nil, err } if character.Author != token.UserID && !token.Permitted("character.edit") { return nil, ErrPermissionDenied }
err = character.AddNick(input.Nick) if err != nil { return nil, err }
go change.Submit("Character", "add.nick", token.UserID, character.ID, map[string]interface{}{ "nick": input.Nick, })
log.ScheduleCharacterUpdate()
return &types.CharacterResolver{C: character}, nil }
|