Gisle Aune
6 years ago
3 changed files with 89 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||
package channels |
|||
|
|||
import ( |
|||
"git.aiterp.net/rpdata/api/models" |
|||
"github.com/globalsign/mgo/bson" |
|||
) |
|||
|
|||
// Edit edits a channels
|
|||
func Edit(channel models.Channel, logged, hub *bool, eventName, locationName *string) (models.Channel, error) { |
|||
mutation := bson.M{} |
|||
|
|||
if logged != nil && *logged != channel.Logged { |
|||
mutation["logged"] = *logged |
|||
} |
|||
if hub != nil && *hub != channel.Hub { |
|||
mutation["hub"] = *hub |
|||
} |
|||
if eventName != nil && *eventName != channel.EventName { |
|||
mutation["eventName"] = *eventName |
|||
} |
|||
if locationName != nil && *locationName != channel.LocationName { |
|||
mutation["locationName"] = *locationName |
|||
} |
|||
|
|||
if len(mutation) == 0 { |
|||
return channel, nil |
|||
} |
|||
|
|||
err := collection.UpdateId(channel.Name, bson.M{"$set": mutation}) |
|||
if err != nil { |
|||
return models.Channel{}, err |
|||
} |
|||
|
|||
return channel, nil |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue