import type { AxiosInstance } from 'axios'; import { type InvoiceDownloadHal, InvoiceHalSchema, type InvoiceHalList, type InvoiceHal, type InvoiceDownloadInput, } from '../../types'; import type { AsyncResult } from '../../utilities'; import { errorResult, successResult } from '../../utilities'; import { ResourceRepository } from '../ResourceRepository'; export class InvoicesResourceRepository extends ResourceRepository< InvoiceHal, InvoiceHalList, undefined, undefined, undefined > { constructor(axios: AxiosInstance, baseUrl: string) { super(axios, baseUrl, { get: InvoiceHalSchema, }); } public async download({ invoiceId, }: InvoiceDownloadInput): AsyncResult { try { const request = await this._axios.get( `${this._baseUrl}/${invoiceId}/download-pdf` ); return successResult(request.data); } catch (error) { return errorResult(error as Error); } } }