cal.pub0.org/packages/lib/apps/getMostPopularApps.ts

28 lines
640 B
TypeScript

import { z } from "zod";
import prisma from "@calcom/prisma";
const getMostPopularApps = 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 getMostPopularApps;