cal/packages/lib/apps/getInstallCountPerApp.ts
Jaideep Guntupalli f4b0772746
refactor: renamed getMostPopularApps function to getInstallCountPerApp (#10140)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-07-17 09:51:35 +00:00

28 lines
646 B
TypeScript

import { z } from "zod";
import prisma from "@calcom/prisma";
const getInstallCountPerApp = async () => {
const mostPopularApps = z.array(z.object({ appId: z.string(), installCount: z.number() })).parse(
await prisma.$queryRaw`
SELECT
c."appId",
COUNT(*)::integer AS "installCount"
FROM
"Credential" c
WHERE
c."appId" IS NOT NULL
GROUP BY
c."appId"
ORDER BY
"installCount" DESC
`
);
return mostPopularApps.reduce((acc, { appId, installCount }) => {
acc[appId] = installCount;
return acc;
}, {} as Record<string, number>);
};
export default getInstallCountPerApp;