sun-pc 5 kuukautta sitten
vanhempi
commit
4834f89fda
1 muutettua tiedostoa jossa 9 lisäystä ja 3 poistoa
  1. 9 3
      src/api/comm.go

+ 9 - 3
src/api/comm.go

@@ -108,7 +108,10 @@ func SortPrev(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			Query:       repo.Map{"_id": id},
 		})
 		currentSort := result["sort"].(int32)
-		currentType := result["type"].(string)
+		currentType := ""
+		if v, ok := result["type"]; ok {
+			currentType = v.(string)
+		}
 		query := repo.Map{"sort": repo.Map{"$gt": int(currentSort)}}
 		if len(currentType) > 0 {
 			query["type"] = currentType
@@ -160,8 +163,11 @@ func SortNext(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			Query:       repo.Map{"_id": id},
 		})
 		currentSort := result["sort"].(int32)
-		currentType := result["type"].(string)
-		query := repo.Map{"sort": repo.Map{"$gt": int(currentSort)}}
+		currentType := ""
+		if v, ok := result["type"]; ok {
+			currentType = v.(string)
+		}
+		query := repo.Map{"sort": repo.Map{"$lt": int(currentSort)}}
 		if len(currentType) > 0 {
 			query["type"] = currentType
 		}