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.

27 lines
613 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. // AddNick adds a nick to a characters
  9. func AddNick(character models.Character, nick string) (models.Character, error) {
  10. for i := range character.Nicks {
  11. if strings.EqualFold(character.Nicks[i], nick) {
  12. return models.Character{}, errors.New("Nick already exists")
  13. }
  14. }
  15. err := collection.UpdateId(character.ID, bson.M{"$push": bson.M{"nicks": nick}})
  16. if err != nil {
  17. return models.Character{}, err
  18. }
  19. character.Nicks = append(character.Nicks, nick)
  20. return character, nil
  21. }