From 3d403bafd1684dad330adeff64df75645967ab5c Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 19 Jul 2023 21:08:08 +0200 Subject: [PATCH] feat: small fixes to billing page, and some types --- src/lib/sdk/billing.ts | 71 ++++++++++++++----- .../billing/availableCredit.svelte | 41 ++++++++--- .../billing/paymentHistory.svelte | 2 +- 3 files changed, 84 insertions(+), 30 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 89f195301..a7861041c 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -38,52 +38,93 @@ export type InvoiceList = { }; export type Credit = { - $id: string; /** * Credit ID. */ - $createdAt: string; + $id: string; /** * Credit creation time in ISO 8601 format. */ - $updatedAt: string; + $createdAt: string; /** * Credit update date in ISO 8601 format. */ - couponId: string; + $updatedAt: string; /** * coupon ID */ - userId: string; + couponId: string; /** * ID of the User. */ - teamId: string; + userId: string; /** * ID of the Team. */ - credits: number; + teamId: string; /** * Provided credit amount */ - creditsUsed: number; + credits: number; /** * Used up credit amount */ - expiration: string; + creditsUsed: number; /** * Credit expiration time in ISO 8601 format. */ - status: string; + expiration: string; /** * Status of the credit. Can be one of `disabled`, `active` or `expired`. */ + status: string; }; export type CreditList = { credits: Credit[]; total: number; }; + +export type Aggregation = { + $id: string; + /** + * Aggregation creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Aggregation update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Beginning date of the invoice. + */ + from: string; + /** + * End date of the invoice. + */ + to: string; + /** + * Total storage usage. + */ + usageStorage: number; + /** + * Total active users for the billing period. + */ + usageUsers: number; + /** + * Total number of executions for the billing period. + */ + usageExecutions: number; + /** + * Total bandwidth usage for the billing period. + */ + usageBandwidth: number; +}; + +export type AggregationList = { + aggregations: Aggregation[]; + total: number; +}; export class Billing { client: Client; @@ -278,10 +319,7 @@ export class Billing { ); } - async listUsage( - organizationId: string, - queries: string[] = [] - ): Promise> { + async listUsage(organizationId: string, queries: string[] = []): Promise { const path = `/organizations/${organizationId}/aggregations`; const params = { organizationId, @@ -298,10 +336,7 @@ export class Billing { ); } - async getUsage( - organizationId: string, - aggregationId: string - ): Promise> { + async getUsage(organizationId: string, aggregationId: string): Promise { const path = `/organizations/${organizationId}/aggregations/${aggregationId}`; const params = { organizationId, diff --git a/src/routes/console/organization-[organization]/billing/availableCredit.svelte b/src/routes/console/organization-[organization]/billing/availableCredit.svelte index 1fc45c30a..2c2581dea 100644 --- a/src/routes/console/organization-[organization]/billing/availableCredit.svelte +++ b/src/routes/console/organization-[organization]/billing/availableCredit.svelte @@ -1,9 +1,9 @@ @@ -56,15 +69,17 @@

Credit balance: ${balance}

- - - - - +
+ + + + + +
{#if $creditList?.total} @@ -88,6 +103,10 @@ {/each}
+
+

Total results: {$creditList?.total}

+ +
{/if} diff --git a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte index ba4e992a4..d0937c962 100644 --- a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte @@ -107,7 +107,7 @@ {/each} -
+

Total results: {$invoiceList?.total}