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.
48 lines
1.2 KiB
48 lines
1.2 KiB
package mutations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/internal/session"
|
|
"git.aiterp.net/rpdata/api/model/change"
|
|
"git.aiterp.net/rpdata/api/model/character"
|
|
"git.aiterp.net/rpdata/api/model/log"
|
|
)
|
|
|
|
// RemoveCharacterNick is args for the addCharacterNick mutation
|
|
type RemoveCharacterNick struct {
|
|
ID string
|
|
Nick string
|
|
}
|
|
|
|
// RemoveCharacterNick resolves the removeCharacterNick mutation
|
|
func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{ Input *RemoveCharacterNick }) (*types.CharacterResolver, error) {
|
|
input := args.Input
|
|
|
|
user := session.FromContext(ctx).User()
|
|
if user == nil || !user.Permitted("member") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
character, err := character.FindID(input.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if character.Author != user.ID && !user.Permitted("character.edit") {
|
|
return nil, ErrPermissionDenied
|
|
}
|
|
|
|
err = character.RemoveNick(input.Nick)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Character", "remove.nick", user.ID, character.ID, map[string]interface{}{
|
|
"nick": input.Nick,
|
|
})
|
|
|
|
log.ScheduleCharacterUpdate()
|
|
|
|
return &types.CharacterResolver{C: character}, nil
|
|
}
|