request method

  1. @override
Future<A> request(
  1. A data, {
  2. bool isTest = false,
})
override

Implementation

@override
Future<A> request(A data, {bool isTest = false}) async {
  final dbStore = DbStoresWeebi().articles;
  final recordSnapshot = await dbStore.find(_database.db);
  if (recordSnapshot.isEmpty) {
    throw 'empty';
  }
  final lineKey = await dbStore.findKey(_database.db,
      finder: Finder(filter: Filter.equals('id', data.calibreId)));
  if (lineKey == null) {
    throw 'lineKey null';
  }
  final lineSnap = await dbStore.record(lineKey).get(_database.db);
  if (lineSnap == null) {
    throw 'lineSnap null';
  }
  final line = CalibreWeebi.fromMap(lineSnap, isProto: false);

  line.articles.add(data);
  final updatedLineMap = await dbStore
      .record(lineKey)
      .update(_database.db, line.toMap(isProto: false));
  if (updatedLineMap == null) {
    throw 'updatedLineMap null';
  }
  if (isTest) {
    final d = CalibreWeebi.fromMap(updatedLineMap, isProto: false)
        .articles
        .firstWhereOrNull((element) =>
            element.calibreId == data.calibreId && element.id == data.id);
    // final dd = d is Article ? d : d as ArticleBasket;
    return d as A;
  } else {
    return data;
  }
}