uploadOne method
dynamic
uploadOne(
- DataValueSet dataValueSet, {
- Dio? dioTestClient,
})
Implementation
uploadOne(DataValueSet dataValueSet, {Dio? dioTestClient}) async {
final uploadFormat = DataValueSet.toUpload(dataValueSet);
final response = await HttpClient.post(
this.apiResourceName as String, uploadFormat,
database: this.database, dioTestClient: dioTestClient);
final importSummary = response.body?['response'];
bool syncFailed = true;
if (!((response.statusCode >= 200 && response.statusCode < 300) ||
response.statusCode == 409)) {
syncFailed = true;
} else {
syncFailed = importSummary['status'] == 'ERROR' ||
importSummary['status'] == 'WARNING';
}
dataValueSet.synced = !syncFailed;
dataValueSet.dirty = true;
dataValueSet.syncFailed = syncFailed;
dataValueSet.lastSyncDate = DateTime.now().toIso8601String();
dataValueSet.lastUpdated = dataValueSet.lastSyncDate;
dataValueSet.lastSyncSummary =
DataValueSetImportSummary.fromJson(importSummary);
return DataValueSetQuery(database: database)
.setData(dataValueSet)
.save(saveOptions: SaveOptions(skipLocalSyncStatus: true));
}