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.

35 lines
817 B

  1. package channels
  2. import (
  3. "git.aiterp.net/rpdata/api/models"
  4. "github.com/globalsign/mgo/bson"
  5. )
  6. // Edit edits a channels
  7. func Edit(channel models.Channel, logged, hub *bool, eventName, locationName *string) (models.Channel, error) {
  8. mutation := bson.M{}
  9. if logged != nil && *logged != channel.Logged {
  10. mutation["logged"] = *logged
  11. }
  12. if hub != nil && *hub != channel.Hub {
  13. mutation["hub"] = *hub
  14. }
  15. if eventName != nil && *eventName != channel.EventName {
  16. mutation["eventName"] = *eventName
  17. }
  18. if locationName != nil && *locationName != channel.LocationName {
  19. mutation["locationName"] = *locationName
  20. }
  21. if len(mutation) == 0 {
  22. return channel, nil
  23. }
  24. err := collection.UpdateId(channel.Name, bson.M{"$set": mutation})
  25. if err != nil {
  26. return models.Channel{}, err
  27. }
  28. return channel, nil
  29. }