From 5a6dce9351da266ced55e55f75dcd55cd93cd759 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 16 Feb 2024 09:44:13 +0100 Subject: [PATCH] fix: add list orgs endpoint --- src/lib/sdk/billing.ts | 18 +++++++++++++++++- src/lib/stores/billing.ts | 4 ++-- src/lib/stores/organization.ts | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 698f78377..66bab7a38 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,5 +1,5 @@ import type { Client, Models, Query } from '@appwrite.io/console'; -import type { Organization } from '../stores/organization'; +import type { Organization, OrganizationList } from '../stores/organization'; import type { PaymentMethod } from '@stripe/stripe-js'; import type { Tier } from '$lib/stores/billing'; @@ -274,6 +274,22 @@ export class Billing { this.client = client; } + async listOrganization(queries: Query[] = []): Promise { + const path = `/organizations`; + const params = { + queries + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'GET', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async createOrganization( organizationId: string, name: string, diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index f05d13381..9eddc4f45 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -268,13 +268,13 @@ export function checkForMarkedForDeletion(org: Organization) { } export async function checkForMissingPaymentMethod() { - const orgs = await sdk.forConsole.teams.list([ + const orgs = await sdk.forConsole.billing.listOrganization([ Query.notEqual('billingPlan', BillingPlan.STARTER), Query.isNull('paymentMethodId'), Query.isNull('backupPaymentMethodId') ]); if (orgs?.total) { - orgMissingPaymentMethod.set(orgs.teams[0] as Organization); + orgMissingPaymentMethod.set(orgs.organizations[0]); headerAlert.add({ id: 'missingPaymentMethod', component: MissingPaymentMethod, diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 38914e5b0..1a532458a 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -22,6 +22,11 @@ export type Organization = Models.Team> & { billingPlanDowngrade?: string; }; +export type OrganizationList = { + organizations: Organization[]; + total: number; +}; + export type BillingLimits = { bandwidth: number; documents: number;