
* Adds available apps * Adds App Model * WIP * Updates seeder script * Seeder fixes * lowercase categories * Upgrades prisma * WIP * WIP * Hopefully fixes circular deps * Type fixes * Fixes seeder * Adds migration to connect Credentials to Apps * Updates app store callbacks * Updates google credentials * Uses dirName from DB * Type fixes * Update reschedule.ts * Seeder fixes * Fixes categories listing * Update index.ts * Update schema.prisma * Updates dependencies * Renames giphy app * Uses dynamic imports for app metadata * Fixes credentials error * Uses dynamic import for api handlers * Dynamic import fixes * Allows for simple folder names in app store * Squashes app migrations * seeder fixes * Fixes dyamic imports * Update apiHandlers.tsx
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
/**
|
|
* This is an example endpoint for an app, these will run under `/api/integrations/[...args]`
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (!req.session?.user?.id) {
|
|
return res.status(401).json({ message: "You must be logged in to do this" });
|
|
}
|
|
const appType = "jitsi_video";
|
|
try {
|
|
const alreadyInstalled = await prisma.credential.findFirst({
|
|
where: {
|
|
type: appType,
|
|
userId: req.session.user.id,
|
|
},
|
|
});
|
|
if (alreadyInstalled) {
|
|
throw new Error("Already installed");
|
|
}
|
|
const installation = await prisma.credential.create({
|
|
data: {
|
|
type: appType,
|
|
key: {},
|
|
userId: req.session.user.id,
|
|
appId: "jitsi",
|
|
},
|
|
});
|
|
if (!installation) {
|
|
throw new Error("Unable to create user credential for jitsivideo");
|
|
}
|
|
} catch (error: unknown) {
|
|
if (error instanceof Error) {
|
|
return res.status(500).json({ message: error.message });
|
|
}
|
|
return res.status(500);
|
|
}
|
|
return res.redirect("/apps/installed");
|
|
}
|