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.
44 lines
1.1 KiB
44 lines
1.1 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"
|
|
)
|
|
|
|
// RemoveCharacterArgs is args for the removeCharacter mutation
|
|
type RemoveCharacterArgs struct {
|
|
ID string
|
|
}
|
|
|
|
// RemoveCharacter resolves the removeCharacter mutation
|
|
func (r *MutationResolver) RemoveCharacter(ctx context.Context, args RemoveCharacterArgs) (*types.CharacterResolver, error) {
|
|
user := session.FromContext(ctx).User()
|
|
if user == nil || !user.Permitted("member") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
character, err := character.FindID(args.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if character.Author != user.ID && !user.Permitted("character.remove") {
|
|
return nil, ErrPermissionDenied
|
|
}
|
|
|
|
err = character.Remove()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Character", "remove", user.ID, character.ID, map[string]interface{}{
|
|
"name": character.Name,
|
|
"author": character.Author,
|
|
"nicks": character.Nicks,
|
|
})
|
|
|
|
return &types.CharacterResolver{C: character}, nil
|
|
}
|