diff --git a/app/public-area/pages/open.tsx b/app/public-area/pages/open.tsx
index 26f55e5..d3d44be 100644
--- a/app/public-area/pages/open.tsx
+++ b/app/public-area/pages/open.tsx
@@ -6,20 +6,24 @@ import getMetrics from "../queries/get-metrics";
import Layout from "../components/layout";
const initialData = {
+ users: 0,
phoneNumbers: 0,
smsExchanged: 0,
minutesCalled: 0,
+ averageMinutesCalled: 0,
};
const OpenMetrics: BlitzPage = () => {
const [metrics] = useQuery(getMetrics, {}, { suspense: false, initialData });
- const { phoneNumbers, smsExchanged, minutesCalled } = metrics ?? initialData;
+ const { users, phoneNumbers, smsExchanged, minutesCalled, averageMinutesCalled } = metrics ?? initialData;
return (
+
+
);
};
diff --git a/app/public-area/queries/get-metrics.ts b/app/public-area/queries/get-metrics.ts
index 30ab57f..ca858e0 100644
--- a/app/public-area/queries/get-metrics.ts
+++ b/app/public-area/queries/get-metrics.ts
@@ -3,7 +3,8 @@ import { resolver } from "blitz";
import db from "../../../db";
export default resolver.pipe(async () => {
- const [phoneNumbers, smsExchanged, allPhoneCalls] = await Promise.all([
+ const [users, phoneNumbers, smsExchanged, allPhoneCalls] = await Promise.all([
+ db.user.count(),
db.phoneNumber.count(),
db.message.count(),
db.phoneCall.findMany(),
@@ -16,10 +17,13 @@ export default resolver.pipe(async () => {
return seconds + Number.parseInt(phoneCall.duration);
}, 0);
const minutesCalled = Math.round(secondsCalled / 60);
+ const averageMinutesCalled = (minutesCalled / allPhoneCalls.length).toFixed(2);
return {
+ users,
phoneNumbers,
smsExchanged,
minutesCalled,
+ averageMinutesCalled,
};
});