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 {
int athletesId,
DateTime date,
}) async {
final List<DbHeartRateZoneSchema> dbHeartRateZoneSchemas =
List<DbHeartRateZoneSchema> dbHeartRateZoneSchemas;
dbHeartRateZoneSchemas =
await DbHeartRateZoneSchema()
.select()
.athletesId
......@@ -150,7 +151,17 @@ class HeartRateZoneSchema {
.toList();
if (dbHeartRateZoneSchemas.isNotEmpty)
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) =>
......
......@@ -57,9 +57,7 @@ class PowerZoneSchema {
Future<List<PowerZone>> get powerZones async {
final List<DbPowerZone> dbPowerZoneList =
await _db.getDbPowerZones().orderBy('lowerLimit').toList();
return dbPowerZoneList
.map(PowerZone.exDb)
.toList();
return dbPowerZoneList.map(PowerZone.exDb).toList();
}
Future<void> addStrydZones() async {
......@@ -201,7 +199,9 @@ class PowerZoneSchema {
String toString() => '< PowerZoneSchema | $name | $date >';
static Future<PowerZoneSchema> getBy({int athletesId, DateTime date}) async {
final List<DbPowerZoneSchema> dbPowerZoneSchemas = await DbPowerZoneSchema()
List<DbPowerZoneSchema> dbPowerZoneSchemas;
dbPowerZoneSchemas = await DbPowerZoneSchema()
.select()
.athletesId
.equals(athletesId)
......@@ -213,7 +213,17 @@ class PowerZoneSchema {
.toList();
if (dbPowerZoneSchemas.isNotEmpty)
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) =>
......
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