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.

39 lines
937 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. channel.Logged = *logged
  12. }
  13. if hub != nil && *hub != channel.Hub {
  14. mutation["hub"] = *hub
  15. channel.Hub = *hub
  16. }
  17. if eventName != nil && *eventName != channel.EventName {
  18. mutation["eventName"] = *eventName
  19. channel.EventName = *eventName
  20. }
  21. if locationName != nil && *locationName != channel.LocationName {
  22. mutation["locationName"] = *locationName
  23. channel.LocationName = *locationName
  24. }
  25. if len(mutation) == 0 {
  26. return channel, nil
  27. }
  28. err := collection.UpdateId(channel.Name, bson.M{"$set": mutation})
  29. if err != nil {
  30. return models.Channel{}, err
  31. }
  32. return channel, nil
  33. }