Skip to main content

Account Analytics

Account Analytics provides filter count statistics for the administrative dashboard, helping administrators understand account distribution across different categories and statuses.

API Endpoints Overview​

MethodEndpointDescription
GET/v1/admin/accounts/filtersGet account filter count statistics

Service Methods & Business Logic​

Account Filter Statistics​

getFilterCounts() - Account distribution statistics for admin dashboard filters

  • Service Method: accountService.getFilterCounts()
  • Controller: accountController.getFilters
  • Route: GET /v1/admin/accounts/filters
  • Parameters: None required
  • Process Flow:
    1. Faceted Aggregation: Uses MongoDB $facet to count accounts across multiple dimensions
    2. Status Counts: Counts active vs archived accounts
    3. Type Counts: Counts main vs sub-accounts
    4. Total Count: Provides overall account count
  • MongoDB Collections: _accounts with aggregation pipeline
  • Returns: Count statistics for each filter category to populate admin dashboard filters

Technical Implementation Details​

Filter Count Aggregation Pipeline​

const getFilterCounts = async () => {
let query = [
{
$facet: {
main: [{ $match: { main: true } }, { $count: 'count' }],
sub: [{ $match: { main: { $ne: true } } }, { $count: 'count' }],
active: [{ $match: { active: true } }, { $count: 'count' }],
archived: [{ $match: { active: { $ne: true } } }, { $count: 'count' }],
totalCount: [
{
$count: 'count',
},
],
},
},
{
$set: {
main: {
$ifNull: [
{
$arrayElemAt: ['$main.count', 0],
},
0,
],
},
sub: {
$ifNull: [
{
$arrayElemAt: ['$sub.count', 0],
},
0,
],
},
active: {
$ifNull: [
{
$arrayElemAt: ['$active.count', 0],
},
0,
],
},
archived: {
$ifNull: [
{
$arrayElemAt: ['$archived.count', 0],
},
0,
],
},
total: {
$ifNull: [
{
$arrayElemAt: ['$totalCount.count', 0],
},
0,
],
},
totalCount: '$$REMOVE',
},
},
];
const filterCounts = await Account.aggregate(query);
return filterCounts;
};

API Response Formats​

Filter Count Statistics Response​

{
"success": true,
"message": "SUCCESS",
"data": [
{
"main": 1250,
"sub": 3420,
"active": 4500,
"archived": 170,
"total": 4670
}
]
}

Query Parameters​

Filter Count Parameters​

  • No parameters required - returns all account filter statistics

Error Handling​

Analytics Error Scenarios​

  • 500 Internal Server Error: Database aggregation failures

Usage Examples​

Get Account Filter Statistics​

GET /v1/admin/accounts/filters
X-Session-Id: MongoDB ObjectId
💬

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:31 AM