addById<T> method
Implementation
Future<Result<T>> addById<T>(JsonObject dto) async {
final localDb = await localRepo();
try {
if (includeLocalTransactions) {
try {
final result = await localDb!.add<T>(dto);
dto = dto.copyWithIDs(IDs.localId(result));
} catch (e, st) {
Logger.error(st, e.toString());
}
}
if (!includeRemoteTransactions) {
return Result.success(obj: dto as T?);
}
// final remoteResult = await remoteRepo!.add<T>(dto);
final remoteResult = await remoteRepo!.addById<T>(dto);
if (remoteResult.hasFailedOrNull) {
dto.isRepoOutOfSync = true;
}
if (includeLocalTransactions) {
await localDb!.add<T>(dto);
}
// TODO - report (Result.error) if an error occurs remotely or locally?
return Result.success(obj: dto as T?);
} catch (e, st) {
return _getErrorLog(msg: e.toString(), stacktrace: st);
} finally {
// await localDb?.close();
}
}