taxDeclarations.js

import Resource from './resources';

/**
 * Retrieve tax declaration information for a specific fiscal link.
 *
 * @extends Resource
 */
class TaxDeclaration extends Resource {
  #endpoint = 'api/tax-declarations/'

  /**
   * Retrieve tax declarations information from a specific fiscal link.
   *
   * @async
   * @param {string} link - UUID4 representation of a link Id.
   * @param {string} yearFrom - Required year from, format is YYYY.
   * @param {string} yearTo - Required year to, format is YYYY.
   * @param {object} options - Optional parameters (token, saveData, attachPDF)
   * @returns {object} Response
   * @throws {RequestError}
   */
  async retrieve(link, yearFrom, yearTo, options = {}) {
    const {
      token, saveData, attachPDF,
    } = options;

    const data = {
      link,
      token,
      year_from: yearFrom,
      year_to: yearTo,
      save_data: saveData,
      attach_pdf: attachPDF,
    };

    const result = await this.session.post(this.#endpoint, data);
    return result;
  }
}

export default TaxDeclaration;