chore: import codes

This commit is contained in:
2026-04-12 12:50:14 -04:00
parent 4bcb4898e8
commit 65ae3c6788
241 changed files with 48834 additions and 1 deletions
@@ -0,0 +1,79 @@
/**
* Admin Stats Actions
* Server-side actions for core dashboard statistics
*
* Module-specific stats are handled by each module's dashboard actions.
* See src/modules/{module}/dashboard/statsActions.js
*
* Usage in your Next.js app:
*
* ```javascript
* // app/(admin)/admin/[...admin]/page.js
* import { protectAdmin } from '@hykocx/zen/admin';
* import { getDashboardStats, getModuleDashboardStats } from '@hykocx/zen/admin/actions';
* import { AdminPagesClient } from '@hykocx/zen/admin/pages';
*
* export default async function AdminPage({ params }) {
* const { user } = await protectAdmin();
*
* // Fetch core dashboard stats
* const statsResult = await getDashboardStats();
* const dashboardStats = statsResult.success ? statsResult.stats : null;
*
* // Fetch module dashboard stats (for dynamic widgets)
* const moduleStats = await getModuleDashboardStats();
*
* return (
* <AdminPagesClient
* params={params}
* user={user}
* dashboardStats={dashboardStats}
* moduleStats={moduleStats}
* />
* );
* }
* ```
*/
'use server';
import { query } from '@hykocx/zen/database';
/**
* 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) {
console.error('Error getting users count:', error);
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) {
console.error('Error getting dashboard stats:', error);
return {
success: false,
error: error.message || 'Failed to get dashboard statistics'
};
}
}