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

  1. package characters
  2. import (
  3. "errors"
  4. "strings"
  5. "git.aiterp.net/rpdata/api/models"
  6. "github.com/globalsign/mgo/bson"
  7. )
  8. // RemoveNick removes a nick to a characters
  9. func RemoveNick(character models.Character, nick string) (models.Character, error) {
  10. index := -1
  11. for i := range character.Nicks {
  12. if strings.EqualFold(character.Nicks[i], nick) {
  13. index = i
  14. break
  15. }
  16. }
  17. if index == -1 {
  18. return models.Character{}, errors.New("Nick does not exist")
  19. }
  20. err := collection.UpdateId(character.ID, bson.M{"$pull": bson.M{"nicks": nick}})
  21. if err != nil {
  22. return models.Character{}, err
  23. }
  24. character.Nicks = append(character.Nicks[:index], character.Nicks[index+1:]...)
  25. return character, nil
  26. }