mirror of
https://github.com/azukaar/Cosmos-Server.git
synced 2026-05-01 00:29:24 -05:00
[release] v0.15.0-unstable17
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cosmos-server",
|
||||
"version": "0.15.0-unstable16",
|
||||
"version": "0.15.0-unstable17",
|
||||
"description": "",
|
||||
"main": "test-server.js",
|
||||
"bugs": {
|
||||
|
||||
@@ -37,12 +37,12 @@ func DeviceList(w http.ResponseWriter, req *http.Request) {
|
||||
if isAdmin {
|
||||
// If admin, get all devices
|
||||
cursor, err := c.Find(nil, map[string]interface{}{})
|
||||
defer cursor.Close(nil)
|
||||
if err != nil {
|
||||
utils.Error("DeviceList: Error fetching devices", err)
|
||||
utils.HTTPError(w, "Error fetching devices", http.StatusInternalServerError, "DL001")
|
||||
return
|
||||
}
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &devices); err != nil {
|
||||
utils.Error("DeviceList: Error decoding devices", err)
|
||||
@@ -55,12 +55,12 @@ func DeviceList(w http.ResponseWriter, req *http.Request) {
|
||||
// If not admin, get user's devices based on their nickname
|
||||
nickname := req.Header.Get("x-cosmos-user")
|
||||
cursor, err := c.Find(nil, map[string]interface{}{"Nickname": nickname})
|
||||
defer cursor.Close(nil)
|
||||
if err != nil {
|
||||
utils.Error("DeviceList: Error fetching devices", err)
|
||||
utils.HTTPError(w, "Error fetching devices", http.StatusInternalServerError, "DL003")
|
||||
return
|
||||
}
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &devices); err != nil {
|
||||
utils.Error("DeviceList: Error decoding devices", err)
|
||||
|
||||
@@ -138,6 +138,7 @@ func GetAllLightHouses() ([]utils.ConstellationDevice, error) {
|
||||
"IsLighthouse": true,
|
||||
"Blocked": false,
|
||||
})
|
||||
defer cursor.Close(nil)
|
||||
cursor.All(nil, &devices)
|
||||
|
||||
if err != nil {
|
||||
@@ -159,6 +160,7 @@ func GetBlockedDevices() ([]utils.ConstellationDevice, error) {
|
||||
cursor, err := c.Find(nil, map[string]interface{}{
|
||||
"Blocked": true,
|
||||
})
|
||||
defer cursor.Close(nil)
|
||||
cursor.All(nil, &devices)
|
||||
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -75,11 +75,11 @@ func AggloMetrics(metricsList []string) []DataDefDB {
|
||||
|
||||
var metrics []DataDefDB
|
||||
cursor, err := c.Find(nil, findOpts)
|
||||
defer cursor.Close(nil)
|
||||
if err != nil {
|
||||
utils.Error("Metrics: Error fetching metrics", err)
|
||||
return []DataDefDB{}
|
||||
}
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &metrics); err != nil {
|
||||
utils.Error("Metrics: Error decoding metrics", err)
|
||||
|
||||
+1
-2
@@ -108,6 +108,7 @@ func ListMetrics(w http.ResponseWriter, req *http.Request) {
|
||||
metrics := []MetricList{}
|
||||
|
||||
cursor, err := c.Find(nil, map[string]interface{}{}, options.Find().SetProjection(bson.M{"Key": 1, "Label":1, "_id": 0}))
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err != nil {
|
||||
utils.Error("metrics: Error while getting metrics", err)
|
||||
@@ -115,8 +116,6 @@ func ListMetrics(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &metrics); err != nil {
|
||||
utils.Error("metrics: Error while decoding metrics", err)
|
||||
utils.HTTPError(w, "metrics decode Error", http.StatusInternalServerError, "UD002")
|
||||
|
||||
@@ -115,6 +115,7 @@ func API_ListEvents(w http.ResponseWriter, req *http.Request) {
|
||||
// .SetProjection(bson.D{{"_id", 1}, {"eventId", 1}, {"date", 1}, {"level", 1}, {"data", 1}})
|
||||
|
||||
cursor, err := c.Find(nil, dbQueryBson, opts)
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err != nil {
|
||||
utils.Error("events: Error while getting events", err)
|
||||
@@ -122,8 +123,6 @@ func API_ListEvents(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &events); err != nil {
|
||||
utils.Error("events: Error while decoding events", err)
|
||||
utils.HTTPError(w, "events decode Error", http.StatusInternalServerError, "UD002")
|
||||
|
||||
@@ -53,6 +53,7 @@ func UserList(w http.ResponseWriter, req *http.Request) {
|
||||
},
|
||||
&fOpt,
|
||||
)
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if errDB != nil {
|
||||
utils.Error("UserList: Error while getting user", errDB)
|
||||
|
||||
+6
-5
@@ -129,12 +129,13 @@ func RefreshUserToken(w http.ResponseWriter, req *http.Request) (utils.User, err
|
||||
|
||||
c, closeDb, errCo := utils.GetEmbeddedCollection(utils.GetRootAppId(), "users")
|
||||
defer closeDb()
|
||||
if errCo != nil {
|
||||
utils.Error("Database Connect", errCo)
|
||||
utils.HTTPError(w, "Database", http.StatusInternalServerError, "DB001")
|
||||
return utils.User{}, errCo
|
||||
}
|
||||
|
||||
if errCo != nil {
|
||||
utils.Error("Database Connect", errCo)
|
||||
utils.HTTPError(w, "Database", http.StatusInternalServerError, "DB001")
|
||||
return utils.User{}, errCo
|
||||
}
|
||||
|
||||
errDB := c.FindOne(nil, map[string]interface{}{
|
||||
"Nickname": nickname,
|
||||
}).Decode(&userInBase)
|
||||
|
||||
+1
-2
@@ -299,14 +299,13 @@ func ListAllUsers(role string) []User {
|
||||
}
|
||||
|
||||
cursor, err := c.Find(nil, condition)
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err != nil {
|
||||
Error("Database: Error while getting users", err)
|
||||
return []User{}
|
||||
}
|
||||
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, &users); err != nil {
|
||||
Error("Database: Error while decoding users", err)
|
||||
return []User{}
|
||||
|
||||
@@ -75,6 +75,7 @@ func NotifGet(w http.ResponseWriter, req *http.Request) {
|
||||
},
|
||||
Limit: &limit,
|
||||
})
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err != nil {
|
||||
Error("Notifications: Error while getting notifications", err)
|
||||
@@ -82,7 +83,6 @@ func NotifGet(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
defer cursor.Close(nil)
|
||||
|
||||
if err = cursor.All(nil, ¬ifications); err != nil {
|
||||
Error("Notifications: Error while decoding notifications", err)
|
||||
|
||||
Reference in New Issue
Block a user