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
906 B

package characters
import (
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Edit sets the fields of metadata. Only non-empty and different fields will be set in the
// database, preventing out of order edits to two fields from conflicting
func Edit(character models.Character, name, shortName, description *string) (models.Character, error) {
changes := bson.M{}
if name != nil && *name != character.Name {
character.Name = *name
changes["name"] = *name
}
if shortName != nil && *shortName != character.ShortName {
character.ShortName = *shortName
changes["shortName"] = *shortName
}
if description != nil && *description != character.Description {
character.Description = *description
changes["description"] = *description
}
err := collection.UpdateId(character.ID, changes)
if err != nil {
return models.Character{}, err
}
return character, nil
}