quickbooks-api
Version:
A modular TypeScript SDK for seamless integration with Intuit QuickBooks APIs. Provides robust authentication handling and future-ready foundation for accounting, payments, and commerce operations.
37 lines (36 loc) • 1.36 kB
JavaScript
// Import the Query Builder
import { plainToClass } from 'class-transformer';
import { Invoice } from '../../../../types/types.js';
/**
* Get Updated Invoices
* @param this - The Invoice API
* @param lastUpdatedDate - The last updated date
* @returns The Invoices
*/
export async function getUpdatedInvoices(lastUpdatedDate, options = {}) {
// Get the Query Builder
const queryBuilder = await this.getQueryBuilder();
// Setup the Last Updated Date Filter
queryBuilder.whereLastUpdatedAfter(lastUpdatedDate);
// Filter by Status (if provided)
if (options.status)
queryBuilder.whereStatus(options.status);
// Setup the Search Options (if provided)
if (options.searchOptions)
queryBuilder.setSearchOptions(options.searchOptions);
// Setup the URL
const url = queryBuilder.build();
// Get the Invoices
const response = await this.apiClient.runRequest(url, { method: 'GET' });
// Format the Response
const invoices = this.formatResponse(response);
// Map the Invoices to Classes
const mappedInvoices = invoices.map((invoice) => plainToClass(Invoice, invoice));
// Setup the Search Response
const searchResponse = {
results: mappedInvoices,
hasNextPage: await this.hasNextPage(queryBuilder),
};
// Return the Invoices
return searchResponse;
}