Appearance
useCommonApis Composable ​
File Information ​
- Path:
app/composables/api/useCommonApis.ts - Purpose: Common API operations for user profile, notifications, and system settings
- Category: API Composable
Overview ​
The useCommonApis composable provides a collection of common API operations used across the application, including user profile management, notifications, and system settings.
Functions ​
getUserProfile ​
Fetches user profile information.
Signature:
typescript
getUserProfile(userId?: string): Promise<any>Parameters:
userId?: string- Optional user ID. If not provided, fetches current user's profile
Returns:
Promise<any>- User profile data
Usage:
typescript
const { getUserProfile } = useCommonApis()
// Get current user profile
const profile = await getUserProfile()
// Get specific user profile
const userProfile = await getUserProfile('user-123')API Endpoint: GET /user/profile?user_id={userId}
updateUserProfile ​
Updates user profile information.
Signature:
typescript
updateUserProfile(profileData: any): Promise<any>Parameters:
profileData: any- Profile data to update
Returns:
Promise<any>- Updated profile data
Usage:
typescript
const { updateUserProfile } = useCommonApis()
const updatedProfile = await updateUserProfile({
name: 'John Doe',
email: '[email protected]',
preferences: { ... }
})API Endpoint: PUT /user/profile
getNotifications ​
Fetches notifications list.
Signature:
typescript
getNotifications(params?: {
page?: number
limit?: number
unread?: boolean
}): Promise<any>Parameters:
params?: object- Optional query parameterspage?: number- Page number (pagination)limit?: number- Items per pageunread?: boolean- Filter unread notifications only
Returns:
Promise<any>- Notifications list
Usage:
typescript
const { getNotifications } = useCommonApis()
// Get all notifications
const notifications = await getNotifications()
// Get unread notifications only
const unread = await getNotifications({ unread: true })
// Get paginated notifications
const page2 = await getNotifications({ page: 2, limit: 20 })API Endpoint: GET /notifications?page={page}&limit={limit}&unread={unread}
markNotificationAsRead ​
Marks a notification as read.
Signature:
typescript
markNotificationAsRead(notificationId: string): Promise<any>Parameters:
notificationId: string- Notification ID to mark as read
Returns:
Promise<any>- Response data
Usage:
typescript
const { markNotificationAsRead } = useCommonApis()
await markNotificationAsRead('notification-123')API Endpoint: POST /notifications/{notificationId}/read
getSystemSettings ​
Fetches system settings.
Signature:
typescript
getSystemSettings(): Promise<any>Returns:
Promise<any>- System settings data
Usage:
typescript
const { getSystemSettings } = useCommonApis()
const settings = await getSystemSettings()
// Use settings for configurationAPI Endpoint: GET /system/settings
Complete Usage Example ​
typescript
const {
getUserProfile,
updateUserProfile,
getNotifications,
markNotificationAsRead,
getSystemSettings
} = useCommonApis()
// Fetch user profile
const profile = await getUserProfile()
// Update profile
await updateUserProfile({
name: 'Updated Name',
email: profile.email
})
// Get notifications
const notifications = await getNotifications({ unread: true })
// Mark notification as read
if (notifications.length > 0) {
await markNotificationAsRead(notifications[0].id)
}
// Get system settings
const settings = await getSystemSettings()Error Handling ​
All functions include error handling with logging:
typescript
catch (error) {
console.error('Failed to fetch user profile:', error)
throw error
}Integration with API Client ​
The composable uses the global $api client:
typescript
const { $api } = useNuxtApp()This provides:
- Automatic authentication
- Error handling
- Request/response interceptors
Related Documentation ​
- Profile Feature - Profile management
- Notifications - Notification system
- API Composables - Other API composables