addition of new dashboard
This commit is contained in:
55
backend/modules/dashboard/service.js
Normal file
55
backend/modules/dashboard/service.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import { getConfig } from "../../common/config.js";
|
||||
import { listCore, listAudit, getEvent, getAgreement, getEventDetails } from "./transactions.js";
|
||||
import { getApiUsage } from "./usage.js";
|
||||
import { getStorage } from "./storage.js";
|
||||
import { getSeries } from "./series.js";
|
||||
import { countApiKeys } from "./account.js";
|
||||
import { getCached } from "./cache.js";
|
||||
import { verifyMany } from "./verify.js";
|
||||
|
||||
// Expensive full per-tenant byte scan that changes slowly.
|
||||
const STORAGE_TTL_MS = 4 * 60 * 60 * 1000;
|
||||
|
||||
export async function summary(userId, { from, to }) {
|
||||
const [apiUsage, apiKeys, storage] = await Promise.all([
|
||||
getApiUsage(userId, { from, to }),
|
||||
countApiKeys(userId),
|
||||
getCached(userId, "storage", STORAGE_TTL_MS, () => getStorage(userId)),
|
||||
]);
|
||||
return {
|
||||
apiUsage,
|
||||
apiKeys,
|
||||
// Externally-facing modules only, not internal ones like `dashboard`.
|
||||
endpoints: Object.values(getConfig().appModules).filter((m) => !m?.internal).length,
|
||||
storage,
|
||||
};
|
||||
}
|
||||
|
||||
export async function transactions(userId, opts) {
|
||||
const { rows, total } = opts.type === "audit"
|
||||
? await listAudit(userId, opts)
|
||||
: await listCore(userId, opts);
|
||||
return { rows, total, limit: opts.limit, offset: opts.offset };
|
||||
}
|
||||
|
||||
export async function series(userId, window) {
|
||||
return getSeries(userId, window);
|
||||
}
|
||||
|
||||
export async function event(userId, eventUuid) {
|
||||
return getEvent(userId, eventUuid);
|
||||
}
|
||||
|
||||
export async function agreement(userId, agreementUuid) {
|
||||
return getAgreement(userId, agreementUuid);
|
||||
}
|
||||
|
||||
export async function verify(userId, targets) {
|
||||
return { results: await verifyMany(userId, targets) };
|
||||
}
|
||||
|
||||
export async function details(userId, eventUuid) {
|
||||
return getEventDetails(userId, eventUuid);
|
||||
}
|
||||
|
||||
export const service = { summary, transactions, series, event, verify, agreement, details };
|
||||
Reference in New Issue
Block a user