Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+22
-9
@@ -18,6 +18,9 @@ type CustomerInvoiceDeps = {
|
||||
loadGateway?: () => BillingGateway | null;
|
||||
};
|
||||
|
||||
const CUSTOMER_INVOICE_PAGE_SIZE = 50;
|
||||
const CUSTOMER_INVOICE_MAX_PAGES = 100;
|
||||
|
||||
export type CustomerBillingInvoiceDownloadTarget = {
|
||||
fileUrl: string;
|
||||
filename: string;
|
||||
@@ -77,11 +80,23 @@ function toServerReachableLagoFileUrl(fileUrl: string): string {
|
||||
|
||||
export async function listCustomerBillingInvoices(input: { tenantId: string; tenantSlug: string }, deps: CustomerInvoiceDeps = {}): Promise<CustomerBillingInvoiceDto[]> {
|
||||
const gateway = resolveGateway(deps);
|
||||
if (!gateway) return [];
|
||||
const invoices = await gateway.listInvoices({ tenantId: input.tenantId, perPage: 50 });
|
||||
return invoices
|
||||
.filter((invoice) => invoice.externalCustomerId === input.tenantId)
|
||||
.map((invoice) => toCustomerInvoice(invoice, input.tenantSlug));
|
||||
if (!gateway) throw new CustomerBillingInvoiceError("CONFIGURATION_MISSING");
|
||||
|
||||
const ownedInvoices: BillingGatewayInvoice[] = [];
|
||||
const seenInvoiceIds = new Set<string>();
|
||||
for (let page = 1; page <= CUSTOMER_INVOICE_MAX_PAGES; page += 1) {
|
||||
const invoices = await gateway.listInvoices({ tenantId: input.tenantId, page, perPage: CUSTOMER_INVOICE_PAGE_SIZE });
|
||||
let addedInvoice = false;
|
||||
for (const invoice of invoices) {
|
||||
if (invoice.externalCustomerId !== input.tenantId || seenInvoiceIds.has(invoice.providerInvoiceId)) continue;
|
||||
seenInvoiceIds.add(invoice.providerInvoiceId);
|
||||
ownedInvoices.push(invoice);
|
||||
addedInvoice = true;
|
||||
}
|
||||
if (invoices.length < CUSTOMER_INVOICE_PAGE_SIZE || !addedInvoice) break;
|
||||
}
|
||||
|
||||
return ownedInvoices.map((invoice) => toCustomerInvoice(invoice, input.tenantSlug));
|
||||
}
|
||||
|
||||
export async function getCustomerBillingInvoiceDownloadUrl(
|
||||
@@ -98,10 +113,8 @@ export async function getCustomerBillingInvoiceDownloadTarget(
|
||||
const gateway = resolveGateway(deps);
|
||||
if (!gateway) throw new CustomerBillingInvoiceError("CONFIGURATION_MISSING");
|
||||
|
||||
const ownedInvoice = (await gateway.listInvoices({ tenantId: input.tenantId, perPage: 50 })).find(
|
||||
(invoice) => invoice.providerInvoiceId === input.invoiceId && invoice.externalCustomerId === input.tenantId
|
||||
);
|
||||
if (!ownedInvoice) {
|
||||
const ownedInvoice = await gateway.getInvoice(input.invoiceId);
|
||||
if (!ownedInvoice || ownedInvoice.externalCustomerId !== input.tenantId) {
|
||||
throw new CustomerBillingInvoiceError("INVOICE_NOT_FOUND");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user