createArticleRetail<A extends ArticleRawAbstract> method

  1. @action
Future<A> createArticleRetail<A extends ArticleRawAbstract>(
  1. A articleData
)

in cloud mode, internet must available

Implementation

@action
Future<A> createArticleRetail<A extends ArticleRawAbstract>(
    A articleData) async {
  final calibreRetail =
      calibresFull.firstWhereOrNull((c) => c.id == articleData.calibreId);
  if (calibreRetail != null) {
    final createdArticle =
        await _articlesService.createArticleRpc.request(articleData);

    //  here we sync this as updateCalibre
    await _updateCalibreServer(
        calibreRetail, true); // connectivity prerequisite
    calibreRetail.articles.add(createdArticle);

    // make sur that the function sparks an update in mobx => View
    final calibreIndex = calibresFull.indexOf(calibreRetail);
    final temp = calibresFull[calibreIndex];
    calibresFull.removeAt(calibreIndex);
    calibresFull.add(temp);
    return createdArticle as A;
  } else {
    throw 'could not find any calibre matching calibreId ${articleData.calibreId} so not creating article ${articleData.designation}';
  }
}