-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public-samples/mint-mobile-app-ncuwqw/src/web/src/services/api/ac…
…counts.ts
- Loading branch information
1 parent
2890112
commit a4cfb9f
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* HUMAN TASKS: | ||
* 1. Verify API endpoint configuration in environment variables | ||
* 2. Set up monitoring for account sync operations | ||
* 3. Configure rate limiting for account sync requests | ||
* 4. Set up error tracking for failed account operations | ||
*/ | ||
|
||
// axios version: ^0.24.0 | ||
import { AxiosResponse } from 'axios'; | ||
import { | ||
Account, | ||
AccountType, | ||
APIResponse, | ||
APIError | ||
} from '../../types'; | ||
import { | ||
apiInstance, | ||
handleApiError | ||
} from '../../utils/api'; | ||
|
||
/** | ||
* Retrieves all financial accounts for the authenticated user | ||
* Requirement: Account Management - Multi-platform user authentication and financial account aggregation | ||
*/ | ||
export async function getAccounts(): Promise<Account[]> { | ||
try { | ||
const response = await apiInstance.get<APIResponse<Account[]>>('/accounts'); | ||
return response.data; | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves details of a specific account by ID | ||
* Requirement: Account Management - Multi-platform user authentication and financial account aggregation | ||
*/ | ||
export async function getAccountById(accountId: string): Promise<Account> { | ||
if (!accountId) { | ||
throw new Error('Account ID is required'); | ||
} | ||
|
||
try { | ||
const response = await apiInstance.get<APIResponse<Account>>(`/accounts/${accountId}`); | ||
return response.data; | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Links a new financial institution account | ||
* Requirement: Account Management - Multi-platform user authentication and financial account aggregation | ||
*/ | ||
export async function linkAccount(linkData: { | ||
institutionId: string; | ||
credentials: Record<string, string>; | ||
accountType: AccountType; | ||
}): Promise<Account> { | ||
if (!linkData.institutionId || !linkData.credentials || !linkData.accountType) { | ||
throw new Error('Institution ID, credentials, and account type are required'); | ||
} | ||
|
||
try { | ||
const response = await apiInstance.post<APIResponse<Account>>('/accounts/link', linkData); | ||
return response.data; | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Unlinks a financial institution account | ||
* Requirement: Account Management - Multi-platform user authentication and financial account aggregation | ||
*/ | ||
export async function unlinkAccount(accountId: string): Promise<void> { | ||
if (!accountId) { | ||
throw new Error('Account ID is required'); | ||
} | ||
|
||
try { | ||
await apiInstance.delete<APIResponse<void>>(`/accounts/${accountId}`); | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Triggers a sync of account data with financial institution | ||
* Requirement: Real-time Updates - Real-time balance updates and cross-platform data synchronization | ||
*/ | ||
export async function syncAccount(accountId: string): Promise<Account> { | ||
if (!accountId) { | ||
throw new Error('Account ID is required'); | ||
} | ||
|
||
try { | ||
const response = await apiInstance.post<APIResponse<Account>>(`/accounts/${accountId}/sync`); | ||
return response.data; | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Updates account settings and preferences | ||
* Requirement: Account Management - Multi-platform user authentication and financial account aggregation | ||
*/ | ||
export async function updateAccountSettings( | ||
accountId: string, | ||
settings: { | ||
isActive?: boolean; | ||
name?: string; | ||
} | ||
): Promise<Account> { | ||
if (!accountId) { | ||
throw new Error('Account ID is required'); | ||
} | ||
|
||
if (!settings || (settings.isActive === undefined && !settings.name)) { | ||
throw new Error('At least one setting must be provided'); | ||
} | ||
|
||
try { | ||
const response = await apiInstance.patch<APIResponse<Account>>( | ||
`/accounts/${accountId}/settings`, | ||
settings | ||
); | ||
return response.data; | ||
} catch (error) { | ||
throw handleApiError(error); | ||
} | ||
} |