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
| Method | Endpoint | Description |
|---|---|---|
GET | /v1/admin/accounts/filters | Get 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:
- Faceted Aggregation: Uses MongoDB
$facetto count accounts across multiple dimensions - Status Counts: Counts active vs archived accounts
- Type Counts: Counts main vs sub-accounts
- Total Count: Provides overall account count
- Faceted Aggregation: Uses MongoDB
- MongoDB Collections:
_accountswith 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