addition of new dashboard
This commit is contained in:
25
backend/modules/dashboard/usage.js
Normal file
25
backend/modules/dashboard/usage.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getPool } from "../../db/index.js";
|
||||
|
||||
// The 'archive' module is surfaced to the UI as "audit".
|
||||
|
||||
export async function getApiUsage(userId, { from, to }) {
|
||||
const client = await getPool();
|
||||
try {
|
||||
const r = (
|
||||
await client.query(
|
||||
`SELECT
|
||||
COALESCE(SUM(CASE WHEN uu.module = 'core' THEN 1 END), 0)::int AS core,
|
||||
COALESCE(SUM(CASE WHEN uu.module = 'archive' THEN 1 END), 0)::int AS audit
|
||||
FROM usage u
|
||||
JOIN usage_url uu ON uu.id = u.usage_url_id
|
||||
WHERE u.user_id = $1
|
||||
AND u.created_ts >= $2::date
|
||||
AND u.created_ts < ($3::date + 1)`,
|
||||
[userId, from, to],
|
||||
)
|
||||
).rows[0];
|
||||
return { core: r.core, audit: r.audit, total: r.core + r.audit };
|
||||
} finally {
|
||||
await client.release();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user