Browse Source

graph2: Added closing of all other logs in the same channel if a log is opened.

1.0
Gisle Aune 6 years ago
parent
commit
ceb2617571
  1. 12
      models/logs/add.go
  2. 11
      models/logs/edit.go

12
models/logs/add.go

@ -8,6 +8,7 @@ import (
"git.aiterp.net/rpdata/api/internal/counter"
"git.aiterp.net/rpdata/api/model/channel"
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Add creates a new Log
@ -39,5 +40,16 @@ func Add(date time.Time, channelName, title, eventName, description string, open
return models.Log{}, err
}
// There can be only one open log in the same channel. TODO: Transaction
if open {
query := bson.M{
"open": true,
"channel": log.ChannelName,
"id": bson.M{"$ne": log.ID},
}
go collection.UpdateAll(query, bson.M{"$set": bson.M{"open": false}})
}
return log, nil
}

11
models/logs/edit.go

@ -35,5 +35,16 @@ func Edit(log models.Log, title *string, event *string, description *string, ope
return models.Log{}, err
}
// There can be only one open log. TODO: Transaction
if changes["open"] != nil && *open {
query := bson.M{
"open": true,
"channel": log.ChannelName,
"id": bson.M{"$ne": log.ID},
}
go collection.UpdateAll(query, bson.M{"$set": bson.M{"open": false}})
}
return log, nil
}
Loading…
Cancel
Save