7ef37e3ebd
- Prefix feature exports with `features/` (auth, admin, provider) - Prefix shared exports with `shared/` (components, icons, lib, config, logger, rate-limit) - Add new explicit exports for `shared/logger`, `shared/config`, and `shared/rate-limit` - Update internal imports to use package self-referencing (`@zen/core/shared/*`) instead of relative paths
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
/**
|
|
* Admin Stats Actions
|
|
* Server-side actions for core dashboard statistics
|
|
*
|
|
* Usage in your Next.js app:
|
|
*
|
|
* ```javascript
|
|
* // app/(admin)/admin/[...admin]/page.js
|
|
* import { protectAdmin } from '@zen/core/features/admin';
|
|
* import { getDashboardStats } from '@zen/core/features/admin/actions';
|
|
* import { AdminPagesClient } from '@zen/core/features/admin/pages';
|
|
*
|
|
* export default async function AdminPage({ params }) {
|
|
* const { user } = await protectAdmin();
|
|
*
|
|
* const statsResult = await getDashboardStats();
|
|
* const dashboardStats = statsResult.success ? statsResult.stats : null;
|
|
*
|
|
* return (
|
|
* <AdminPagesClient
|
|
* params={params}
|
|
* user={user}
|
|
* dashboardStats={dashboardStats}
|
|
* />
|
|
* );
|
|
* }
|
|
* ```
|
|
*/
|
|
|
|
'use server';
|
|
|
|
import { query } from '@zen/core/database';
|
|
import { fail } from '@zen/core/shared/logger';
|
|
|
|
/**
|
|
* Get total number of users
|
|
* @returns {Promise<number>}
|
|
*/
|
|
async function getTotalUsersCount() {
|
|
try {
|
|
const result = await query(
|
|
`SELECT COUNT(*) as count FROM zen_auth_users`
|
|
);
|
|
return parseInt(result.rows[0].count) || 0;
|
|
} catch (error) {
|
|
fail(`Error getting users count: ${error.message}`);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get core dashboard statistics
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
export async function getDashboardStats() {
|
|
try {
|
|
const totalUsers = await getTotalUsersCount();
|
|
|
|
return {
|
|
success: true,
|
|
stats: {
|
|
totalUsers,
|
|
}
|
|
};
|
|
} catch (error) {
|
|
fail(`Error getting dashboard stats: ${error.message}`);
|
|
return {
|
|
success: false,
|
|
error: error.message || 'Failed to get dashboard statistics'
|
|
};
|
|
}
|
|
}
|