first commit
This commit is contained in:
27
calcom/packages/lib/apps/getInstallCountPerApp.ts
Normal file
27
calcom/packages/lib/apps/getInstallCountPerApp.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user