Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"@ai-sdk/svelte": "^1.1.24",
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@f08cb74",
"@appwrite.io/pink-icons": "0.25.0",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@077179c",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@3a17fe8",
"@appwrite.io/pink-legacy": "^1.0.3",
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@077179c",
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@3a17fe8",
"@faker-js/faker": "^9.9.0",
"@popperjs/core": "^2.11.8",
"@sentry/sveltekit": "^8.38.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum Dependencies {
CREDIT = 'dependency:credit',
INVOICES = 'dependency:invoices',
ADDRESS = 'dependency:address',
BILLING_AGGREGATION = 'dependency:billing_aggregation',
UPGRADE_PLAN = 'dependency:upgrade_plan',
ORGANIZATIONS = 'dependency:organizations',
PAYMENT_METHODS = 'dependency:paymentMethods',
Expand Down
16 changes: 14 additions & 2 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,24 @@ export class Billing {
);
}

async getAggregation(organizationId: string, aggregationId: string): Promise<AggregationTeam> {
async getAggregation(
organizationId: string,
aggregationId: string,
limit?: number,
offset?: number
): Promise<AggregationTeam> {
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
const params = {
const params: {
organizationId: string;
aggregationId: string;
limit?: number;
offset?: number;
Comment on lines +947 to +948
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the endpoint now allow these? 👀
quite nice if it fully supports pagination, does it also support Query.select?

speaking of queries, lets make this as a queries param instead of passing every param individually. Refer - https://github.com/appwrite/console/blob/main/src/lib/sdk/billing.ts#L455

} = {
organizationId,
aggregationId
};
if (typeof limit === 'number') params.limit = limit;
if (typeof offset === 'number') params.offset = offset;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
availableCredit={data?.availableCredit}
currentPlan={data?.currentPlan}
nextPlan={data?.nextPlan}
currentAggregation={data?.billingAggregation} />
currentAggregation={data?.billingAggregation}
limit={data?.limit}
offset={data?.offset}
aggregationKey={data?.aggregationKey} />
{:else}
<PlanSummaryOld
availableCredit={data?.availableCredit}
Expand Down
18 changes: 15 additions & 3 deletions src/routes/(console)/organization-[organization]/billing/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';
import { base } from '$app/paths';

export const load: PageLoad = async ({ parent, depends }) => {
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';

export const load: PageLoad = async ({ parent, depends, url, route }) => {
const { organization, scopes, currentPlan, countryList, locale } = await parent();

if (!scopes.includes('billing.read')) {
Expand All @@ -19,6 +21,8 @@ export const load: PageLoad = async ({ parent, depends }) => {
depends(Dependencies.CREDIT);
depends(Dependencies.INVOICES);
depends(Dependencies.ADDRESS);
//aggregation reloads on page param changes
depends(Dependencies.BILLING_AGGREGATION);

const billingAddressId = (organization as Organization)?.billingAddressId;
const billingAddressPromise: Promise<Address> = billingAddressId
Expand All @@ -34,9 +38,14 @@ export const load: PageLoad = async ({ parent, depends }) => {
*/
let billingAggregation = null;
try {
const currentPage = getPage(url) || 1;
const limit = getLimit(url, route, 5);
const offset = pageToOffset(currentPage, limit);
billingAggregation = await sdk.forConsole.billing.getAggregation(
organization.$id,
(organization as Organization)?.billingAggregationId
(organization as Organization)?.billingAggregationId,
limit,
offset
);
} catch (e) {
// ignore error
Expand Down Expand Up @@ -84,6 +93,9 @@ export const load: PageLoad = async ({ parent, depends }) => {
areCreditsSupported,
countryList,
locale,
nextPlan: billingPlanDowngrade
nextPlan: billingPlanDowngrade,
// expose pagination for components
limit: getLimit(url, route, 5),
offset: pageToOffset(getPage(url) || 1, getLimit(url, route, 5))
Comment on lines +98 to +99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Avoid recalculating limit and offset.

limit and offset are already computed at lines 42-43. Recalculating them here duplicates logic and risks inconsistency.

Apply this diff to reuse the existing values:

-        limit: getLimit(url, route, 5),
-        offset: pageToOffset(getPage(url) || 1, getLimit(url, route, 5))
+        limit,
+        offset
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
limit: getLimit(url, route, 5),
offset: pageToOffset(getPage(url) || 1, getLimit(url, route, 5))
- limit: getLimit(url, route, 5),
limit,
offset
🤖 Prompt for AI Agents
In src/routes/(console)/organization-[organization]/billing/+page.ts around
lines 98 to 99 (previously computed at lines 42-43), the code recalculates limit
and offset via getLimit/getPage/pageToOffset; instead reuse the existing limit
and offset variables computed earlier instead of calling getLimit/getPage
again—replace the duplicate calls so the object uses the previously computed
limit and the previously computed offset (or compute offset once using the
existing page and limit variables) to avoid logic duplication and inconsistency.

};
};
Loading