diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index a6610f513..6eb33f57c 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -4,7 +4,7 @@ import { Card, Divider, Layout, Typography } from '@appwrite.io/pink-svelte'; import { CreditsApplied } from '.'; import { sdk } from '$lib/stores/sdk'; - import { AppwriteException, type Models } from '@appwrite.io/console'; + import { AppwriteException, BillingPlan, type Models } from '@appwrite.io/console'; import DiscountsApplied from './discountsApplied.svelte'; export let billingPlan: string; @@ -23,12 +23,15 @@ collaborators: string[], couponId: string | undefined ) { + /* TODO: @itznotabug - temporary fix */ + const billingPlanTyped = billingPlan as BillingPlan; + try { - estimation = await sdk.forConsole.billing.estimationCreateOrganization( - billingPlan, - couponId === '' ? null : couponId, - collaborators ?? [] - ); + estimation = await sdk.forConsole.organizations.estimationCreateOrganization({ + billingPlan: billingPlanTyped, + invites: collaborators ?? [], + couponId: couponId === '' ? null : couponId + }); } catch (e) { if (e instanceof AppwriteException) { if ( diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 65ead67fa..6b969ed60 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -57,62 +57,6 @@ export class Billing { ); } - async estimationCreateOrganization( - billingPlan: string, - couponId: string = null, - invites: Array = [] - ): Promise { - const path = `/organizations/estimations/create-organization`; - const params = { - billingPlan, - couponId, - invites - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async deleteOrganization(organizationId: string): Promise { - const path = `/organizations/${organizationId}`; - const params = { - organizationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'DELETE', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async estimationDeleteOrganization( - organizationId: string - ): Promise { - const path = `/organizations/${organizationId}/estimations/delete-organization`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json' - }); - } - - async getOrganizationPlan(organizationId: string): Promise { - const path = `/organizations/${organizationId}/plan`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json' - }); - } - async listPlans(queries: string[] = []): Promise { const path = `/console/plans`; const uri = new URL(this.client.config.endpoint + path); @@ -137,14 +81,6 @@ export class Billing { }); } - async getRoles(organizationId: string): Promise { - const path = `/organizations/${organizationId}/roles`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json' - }); - } - async updatePlan( organizationId: string, billingPlan: string, diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 45d8340f8..7f84d72c7 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -317,7 +317,9 @@ export async function checkForProjectsLimit(org: Models.Organization, orgProject if (!isCloud) return; if (!org) return; - const plan = await sdk.forConsole.billing.getOrganizationPlan(org.$id); + const plan = await sdk.forConsole.organizations.getPlan({ + organizationId: org.$id + }); if (!plan) return; if (plan.$id !== BillingPlan.FREE) return; diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index e84483520..1e0715859 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -254,7 +254,9 @@ $: if (!isNewOrg) { (async () => { - currentPlan = await sdk.forConsole.billing.getOrganizationPlan(selectedOrgId); + currentPlan = await sdk.forConsole.organizations.getPlan({ + organizationId: selectedOrgId + }); })(); loadPaymentMethods(); } diff --git a/src/routes/(console)/organization-[organization]/+layout.ts b/src/routes/(console)/organization-[organization]/+layout.ts index f8e3d1388..7b63473f1 100644 --- a/src/routes/(console)/organization-[organization]/+layout.ts +++ b/src/routes/(console)/organization-[organization]/+layout.ts @@ -31,8 +31,13 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => { try { if (isCloud) { [{ roles, scopes }, currentPlan] = await Promise.all([ - sdk.forConsole.billing.getRoles(params.organization), - sdk.forConsole.billing.getOrganizationPlan(params.organization) + sdk.forConsole.organizations.getScopes({ + organizationId: params.organization + }), + + sdk.forConsole.organizations.getPlan({ + organizationId: params.organization + }) ]); if (scopes.includes('billing.read')) { diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index ae22262f4..51a1d483a 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -28,7 +28,9 @@ async function deleteOrg() { try { if (isCloud) { - await sdk.forConsole.billing.deleteOrganization($organization.$id); + await sdk.forConsole.organizations.delete({ + organizationId: $organization.$id + }); } else { await sdk.forConsole.teams.delete({ teamId: $organization.$id @@ -82,9 +84,9 @@ if (isCloud) { try { error = ''; - estimation = await sdk.forConsole.billing.estimationDeleteOrganization( - $organization.$id - ); + estimation = await sdk.forConsole.organizations.estimationDeleteOrganization({ + organizationId: $organization.$id + }); } catch (e) { error = e.message; } diff --git a/src/routes/(console)/project-[region]-[project]/+layout.ts b/src/routes/(console)/project-[region]-[project]/+layout.ts index 818eba1a8..4db871851 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.ts +++ b/src/routes/(console)/project-[region]-[project]/+layout.ts @@ -33,7 +33,11 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => { (sdk.forConsole.teams.get({ teamId: project.teamId }) as Promise) : organization, sdk.forConsoleIn(project.region).console.variables(), - isCloud ? sdk.forConsole.billing.getRoles(project.teamId) : null, + isCloud + ? sdk.forConsole.organizations.getScopes({ + organizationId: project.teamId + }) + : null, loadAvailableRegions(project.teamId) ]); @@ -56,7 +60,9 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => { const organizationPlan = includedInBasePlans ? plansInfo.get(organization?.billingPlan) : isCloud - ? await sdk.forConsole.billing.getOrganizationPlan(organization?.$id) + ? await sdk.forConsole.organizations.getPlan({ + organizationId: organization?.$id + }) : null; const roles = rolesResult?.roles ?? defaultRoles;