add some metrics

This commit is contained in:
m5r
2021-10-21 00:24:29 +02:00
parent 5f6100b0bb
commit 730030f6f1
2 changed files with 10 additions and 2 deletions

View File

@ -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,
};
});