Skip to main content

fetchUserStat

Fetches statistics for a specific user by their ID.
userId
string
required
The ID of the user to fetch statistics for
Returns: Promise<void>
Note: This function currently doesn’t return the fetched data. It appears to be incomplete in the source code (line 11-15 in userStats.service.ts).
Error Handling: Throws error if fetching fails. Error is logged and re-thrown.
import { fetchUserStat } from '@/services/userStats.service';

try {
  await fetchUserStat('user123');
} catch (error) {
  console.error('Failed to fetch user stats:', error);
}

fetchUserStatsByUserId

Retrieves user statistics by user ID, sorted by creation date.
userId
string
required
The ID of the user to fetch statistics for
Returns: Promise<{ rows: UserStats[], total: number }>
rows
UserStats[]
Array of user statistics records
total
number
Total number of matching records
Error Handling: Throws error if fetching fails. Error is logged and re-thrown.
import { fetchUserStatsByUserId } from '@/services/userStats.service';

const data = await fetchUserStatsByUserId('user123');
const stats = data.rows[0];

// Access user statistics
console.log('Posts:', stats.postsCount);
console.log('Comments:', stats.commentsCount);
console.log('Likes:', stats.likesCount);

Build docs developers (and LLMs) love