This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user