save method

Future<Quote> save(
  1. Quote quote, {
  2. QuoteAction? action,
})

Persist quote to the server

Implementation

Future<Quote> save(Quote quote, {QuoteAction? action}) async {
  dynamic response;
  String url;

  if (quote.id.isEmpty) {
    url = '${InvoiceNinjaAdmin.url}/api/v1/quotes';
  } else {
    url = '${InvoiceNinjaAdmin.url}/api/v1/quotes/${quote.id}';
  }

  if (action == QuoteAction.approve) {
    url += '?approve=true';
  } else if (action == QuoteAction.markSent) {
    url += '?mark_sent=true';
  } else if (action == QuoteAction.convertToInvoice) {
    url += '?convert=true';
  } else if (action == QuoteAction.sendEmail) {
    url += '?send_email=true';
  }

  if (quote.id.isEmpty) {
    response = await WebClient()
        .post(url, token: InvoiceNinjaAdmin.token, data: quote.toJson());
  } else {
    response = await WebClient()
        .put(url, token: InvoiceNinjaAdmin.token, data: quote.toJson());
  }

  return QuoteItem.fromJson(response).data;
}