updateBillNote method

Future<AnybillResult<BillBaseDto>> updateBillNote(
  1. {int requestCount = 2,
  2. required String billId,
  3. required String? note}
)

Updates note of the given bill Id

  • requestCount can be used to determine the number of repeated requests before a failure is returned if the call is not successful.

  • billId of the bill that is supposed to be updated.

  • note with the text that should be saved.

Returns a AnybillResult.success that contains the status code and the updated bill object

Throws a AnybillResult.failure with the specified information gained from the API. This could be a DioException when a generic errors occurred or a different Exception for critical errors that couldn't be caught.

Implementation

Future<AnybillResult<BillBaseDto>> updateBillNote({
  int requestCount = 2,
  required String billId,
  required String? note,
}) async {
  AnybillLogger.info("Tried to update bill note $billId");
  try {
    var bill = await _billStore.getBillById(billId);

    if (bill == null) {
      await getBills();
      bill = await _billStore.getBillById(billId);
      if (bill == null) {
        return AnybillResult.failure(
          code: HttpStatus.notFound,
          type: AnybillErrorType.genericError,
          message: "bill not found",
        );
      }
    }

    var updateBillDto = bill.getUpdateBillDto();
    updateBillDto.comment = note;

    return await _updateBill(
      billId: billId,
      upsertBill: updateBillDto,
    );
  }
  // ----------------------------------------------------------------
  catch (error, stacktrace) {
    return ErrorHandler.handleError(
      error,
      stacktrace,
      requestCount: requestCount,
      request: () => updateBillNote(
        requestCount: requestCount - 1,
        billId: billId,
        note: note,
      ),
      event: "updateBillNote",
      library: runtimeType.toString(),
    );
  }
}