Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,38 @@
import { getDbClient, type DbClient } from "./client.server.js";
export type AdminKpiCounts = {
added: number;
total: number;
};
export type AdminKpiPeriod = {
gte?: Date;
};
export type AdminKpiClient = Pick<DbClient, "tenant" | "log">;
function buildCreatedAtWhere({ gte }: AdminKpiPeriod) {
return gte ? { createdAt: { gte } } : undefined;
}
export async function getAdminTenantKpiCounts(period: AdminKpiPeriod, client: AdminKpiClient = getDbClient()): Promise<AdminKpiCounts> {
const addedWhere = buildCreatedAtWhere(period);
const [total, added] = await Promise.all([
client.tenant.count(),
client.tenant.count(addedWhere ? { where: addedWhere } : undefined),
]);
return { added, total };
}
export async function getAdminActiveUserKpiCounts(period: AdminKpiPeriod, client: AdminKpiClient = getDbClient()): Promise<AdminKpiCounts> {
const addedWhere = buildCreatedAtWhere(period);
const [totalGroups, addedGroups] = await Promise.all([
client.log.groupBy({ by: ["userId"] }),
addedWhere
? client.log.groupBy({ by: ["userId"], where: addedWhere })
: client.log.groupBy({ by: ["userId"] }),
]);
return { added: addedGroups.length, total: totalGroups.length };
}