cal.pub0.org/apps/web/pages/api/app-store/installed.ts

38 lines
991 B
TypeScript
Raw Normal View History

import type { NextApiRequest, NextApiResponse } from "next";
2022-05-14 03:02:10 +00:00
import prisma from "@calcom/prisma";
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-05-14 03:02:10 +00:00
const installedApp = await prisma.credential.findFirst({
where: {
type: appCredentialType as string,
userId: userId,
},
});
if (installedApp && !!installedApp.key) {
res.status(200);
} else {
res.status(404);
}
} catch (error) {
console.log(error);
res.status(500);
}
} else {
res.status(400);
}
res.end();
}