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.
 
 

32 lines
709 B

package characters
import (
"errors"
"strings"
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// RemoveNick removes a nick to a characters
func RemoveNick(character models.Character, nick string) (models.Character, error) {
index := -1
for i := range character.Nicks {
if strings.EqualFold(character.Nicks[i], nick) {
index = i
break
}
}
if index == -1 {
return models.Character{}, errors.New("Nick does not exist")
}
err := collection.UpdateId(character.ID, bson.M{"$pull": bson.M{"nicks": nick}})
if err != nil {
return models.Character{}, err
}
character.Nicks = append(character.Nicks[:index], character.Nicks[index+1:]...)
return character, nil
}