2022-04-20 21:37:25 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
2022-04-20 21:37:25 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
req.session = await getSession({ req });
|
|
|
|
if (req.method === "GET" && req.session && req.session.user.id && req.query) {
|
|
|
|
const { "app-credential-type": appCredentialType } = req.query;
|
|
|
|
if (!appCredentialType && Array.isArray(appCredentialType)) {
|
|
|
|
return res.status(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
const userId = req.session.user.id;
|
|
|
|
try {
|
2022-06-01 17:24:41 +00:00
|
|
|
const installedApp = await prisma.credential.findMany({
|
2022-04-20 21:37:25 +00:00
|
|
|
where: {
|
|
|
|
type: appCredentialType as string,
|
|
|
|
userId: userId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-06-01 17:24:41 +00:00
|
|
|
if (installedApp && !!installedApp.length) {
|
|
|
|
res.json({ count: installedApp.length });
|
2022-04-20 21:37:25 +00:00
|
|
|
} else {
|
|
|
|
res.status(404);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2022-05-11 05:41:09 +00:00
|
|
|
console.log(error);
|
2022-04-20 21:37:25 +00:00
|
|
|
res.status(500);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.status(400);
|
|
|
|
}
|
|
|
|
res.end();
|
|
|
|
}
|