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.
35 lines (34 loc) • 1.1 kB
JavaScript
// Import the Query Builder
import { plainToClass } from 'class-transformer';
import { Bill } from '../../../../types/types.js';
/**
* Get Bill by ID
* @param this - The Bill API
* @param id - The ID of the bill
* @returns The Bill
*/
export async function getBillById(id) {
// Get the Query Builder
const queryBuilder = await this.getQueryBuilder();
// Setup ID Filter
queryBuilder.whereId(id);
// Setup the URL
const url = queryBuilder.build();
// Get the Bill
const { responseData, intuitTID } = await this.apiClient.runRequest(url, { method: 'GET' });
// Check if the Response Failed to find an Bill
if (!responseData)
return { bill: null, intuitTID };
// Format the Response
const bills = await this.formatResponse(responseData);
// Convert the Bill to a Class
const bill = bills[0] ? plainToClass(Bill, bills[0]) : null;
// Check if the Bill is valid and set the API Client
if (bill)
bill.setApiClient(this.apiClient);
// Return the Bill with Intuit TID
return {
bill,
intuitTID,
};
}