Commit 34552fa4 authored by Stefan Haslinger's avatar Stefan Haslinger

fallback to oldest HeartRateZoneSchema / PowerZoneSchema, if no schema old enough can be found

parent bf394319
...@@ -137,7 +137,8 @@ class HeartRateZoneSchema { ...@@ -137,7 +137,8 @@ class HeartRateZoneSchema {
int athletesId, int athletesId,
DateTime date, DateTime date,
}) async { }) async {
final List<DbHeartRateZoneSchema> dbHeartRateZoneSchemas = List<DbHeartRateZoneSchema> dbHeartRateZoneSchemas;
dbHeartRateZoneSchemas =
await DbHeartRateZoneSchema() await DbHeartRateZoneSchema()
.select() .select()
.athletesId .athletesId
...@@ -150,7 +151,17 @@ class HeartRateZoneSchema { ...@@ -150,7 +151,17 @@ class HeartRateZoneSchema {
.toList(); .toList();
if (dbHeartRateZoneSchemas.isNotEmpty) if (dbHeartRateZoneSchemas.isNotEmpty)
return HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first); return HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first);
return null; else
dbHeartRateZoneSchemas = await DbHeartRateZoneSchema()
.select()
.athletesId
.equals(athletesId)
.orderBy('date')
.top(1)
.toList();
return (dbHeartRateZoneSchemas.isNotEmpty)
? HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first)
: null;
} }
static HeartRateZoneSchema exDb(DbHeartRateZoneSchema db) => static HeartRateZoneSchema exDb(DbHeartRateZoneSchema db) =>
......
...@@ -57,9 +57,7 @@ class PowerZoneSchema { ...@@ -57,9 +57,7 @@ class PowerZoneSchema {
Future<List<PowerZone>> get powerZones async { Future<List<PowerZone>> get powerZones async {
final List<DbPowerZone> dbPowerZoneList = final List<DbPowerZone> dbPowerZoneList =
await _db.getDbPowerZones().orderBy('lowerLimit').toList(); await _db.getDbPowerZones().orderBy('lowerLimit').toList();
return dbPowerZoneList return dbPowerZoneList.map(PowerZone.exDb).toList();
.map(PowerZone.exDb)
.toList();
} }
Future<void> addStrydZones() async { Future<void> addStrydZones() async {
...@@ -201,7 +199,9 @@ class PowerZoneSchema { ...@@ -201,7 +199,9 @@ class PowerZoneSchema {
String toString() => '< PowerZoneSchema | $name | $date >'; String toString() => '< PowerZoneSchema | $name | $date >';
static Future<PowerZoneSchema> getBy({int athletesId, DateTime date}) async { static Future<PowerZoneSchema> getBy({int athletesId, DateTime date}) async {
final List<DbPowerZoneSchema> dbPowerZoneSchemas = await DbPowerZoneSchema() List<DbPowerZoneSchema> dbPowerZoneSchemas;
dbPowerZoneSchemas = await DbPowerZoneSchema()
.select() .select()
.athletesId .athletesId
.equals(athletesId) .equals(athletesId)
...@@ -213,7 +213,17 @@ class PowerZoneSchema { ...@@ -213,7 +213,17 @@ class PowerZoneSchema {
.toList(); .toList();
if (dbPowerZoneSchemas.isNotEmpty) if (dbPowerZoneSchemas.isNotEmpty)
return PowerZoneSchema._fromDb(dbPowerZoneSchemas.first); return PowerZoneSchema._fromDb(dbPowerZoneSchemas.first);
return null; else
dbPowerZoneSchemas = await DbPowerZoneSchema()
.select()
.athletesId
.equals(athletesId)
.orderBy('date')
.top(1)
.toList();
return (dbPowerZoneSchemas.isNotEmpty)
? PowerZoneSchema._fromDb(dbPowerZoneSchemas.first)
: null;
} }
static PowerZoneSchema exDb(DbPowerZoneSchema db) => static PowerZoneSchema exDb(DbPowerZoneSchema db) =>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment