Refactor subscription and order retrieval methods

The changes refactor how subscription and order data is retrieved throughout the codebase. This includes renaming methods from 'getSubscriptionData' and 'getOrdersData' to 'getSubscription' and 'getOrder' respectively. The code for obtaining these subscriptions and orders has been rewritten for improved clarity and error handling.
This commit is contained in:
giancarlo
2024-04-24 12:07:09 +07:00
parent abd0771c4a
commit dbdccc59bc
4 changed files with 74 additions and 32 deletions

View File

@@ -29,6 +29,43 @@ export class TeamAccountsApi {
return data;
}
/**
* @name getSubscription
* @description Get the subscription data for the account.
* @param accountId
*/
async getSubscription(accountId: string) {
const { data, error } = await this.client
.from('subscriptions')
.select('*')
.eq('account_id', accountId)
.maybeSingle();
if (error) {
throw error;
}
return data;
}
/**
* Get the orders data for the given account.
* @param accountId
*/
async getOrder(accountId: string) {
const response = await this.client
.from('orders')
.select('*, items: order_items !inner (*)')
.eq('account_id', accountId)
.maybeSingle();
if (response.error) {
throw response.error;
}
return response.data;
}
/**
* @name getAccountWorkspace
* @description Get the account workspace data.