UNPKG

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.

45 lines (44 loc) 2.11 kB
// Import the Query Builder import { plainToClass } from 'class-transformer'; import { Customer } from '../../../../types/types.js'; /** * Retrieves customers updated within a specified date range. * * This asynchronous function constructs a query to filter customers based on their last update timestamps, * applies optional search configurations, and retrieves customer data via a GET request. The response is * formatted into a structured search response containing the customers and a flag indicating if more pages of * results are available. * * @param startDate - The beginning of the date range for filtering customer updates. * @param endDate - The end of the date range for filtering customer updates. * @param options - Optional search configuration for additional filtering, pagination, or sorting. * @returns A promise that resolves to a search response with the filtered customers and pagination details. */ export async function getCustomersForDateRange(startDate, endDate, options = {}) { // Ensure the Start Date is Before the End Date if (startDate > endDate) throw new Error('Start date must be before end date'); // Get the Query Builder const queryBuilder = await this.getQueryBuilder(); // Setup the Date Range Filters queryBuilder.whereLastUpdatedAfter(startDate); queryBuilder.whereLastUpdatedBefore(endDate); // Setup the Search Options (if provided) if (options.searchOptions) queryBuilder.setSearchOptions(options.searchOptions); // Setup the URL const url = queryBuilder.build(); // Get the Customers const response = await this.apiClient.runRequest(url, { method: 'GET' }); // Format the Response const customers = this.formatResponse(response); // Map the Customers to Classes const mappedCustomers = customers.map((customer) => plainToClass(Customer, customer)); // Setup the Search Response const searchResponse = { results: mappedCustomers, hasNextPage: await this.hasNextPage(queryBuilder), }; // Return the Customers return searchResponse; }