Merge pull request #825 from appwrite/fix-add-list-orgs-endpoint

fix: add list orgs endpoint
This commit is contained in:
Christy Jacob
2024-02-16 15:13:45 +05:30
committed by GitHub
4 changed files with 26 additions and 7 deletions
@@ -2,7 +2,6 @@
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { toLocaleDate } from '$lib/helpers/date';
import { HeaderAlert } from '$lib/layout';
import { orgMissingPaymentMethod } from '$routes/console/store';
</script>
@@ -12,9 +11,8 @@
type="error"
title={`Payment method required for ${$orgMissingPaymentMethod.name}`}>
<svelte:fragment>
Add a payment method to {$orgMissingPaymentMethod.name} before {toLocaleDate(
$orgMissingPaymentMethod.billingCurrentInvoiceDate
)} to avoid service interruptions to your projects.
Add a payment method to {$orgMissingPaymentMethod.name} to avoid service interruptions to
your projects.
</svelte:fragment>
<svelte:fragment slot="buttons">
<Button
+17 -1
View File
@@ -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<OrganizationList> {
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,
+2 -2
View File
@@ -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.teams[0]);
headerAlert.add({
id: 'missingPaymentMethod',
component: MissingPaymentMethod,
+5
View File
@@ -22,6 +22,11 @@ export type Organization = Models.Team<Record<string, unknown>> & {
billingPlanDowngrade?: string;
};
export type OrganizationList = {
teams: Organization[];
total: number;
};
export type BillingLimits = {
bandwidth: number;
documents: number;