* First round of changes * Some missing styling * Last round of core changes * Color tweaks * Improving code readability * Reverting unneeded changes * Reverting yarn.lock * Removing yarn.lock * Empty state updated * Fixing webhook test * Cleaning up code * Fixing test and simplifying code a bit * Merging API Keys into developer section * Unifying Empty Screen with monorepo version * Cleaning up * Installed apps logic consistency + cleaning up * Type fixes * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> Co-authored-by: alannnc <alannnc@gmail.com> * Improvements, still WIP * Update apps/web/pages/apps/installed.tsx Co-authored-by: Omar López <zomars@me.com> * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> * App active install status * Apple Calendar setup, Daily.co preinstalled * Final pass * Minor tweaks * Conflicts with migration ignored * Fixing merge * Fixing merge yet again * Adopting main changes * Removing unneeded data-testid * Fixing reported bugs * Simplifying webhook query * Moving teams settings tab to second Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: alannnc <alannnc@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { symmetricEncrypt } from "@calcom/lib/crypto";
|
|
import logger from "@calcom/lib/logger";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { CalendarService } from "../lib";
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (req.method === "POST") {
|
|
const { username, password } = req.body;
|
|
// Get user
|
|
const user = await prisma.user.findFirst({
|
|
rejectOnNotFound: true,
|
|
where: {
|
|
id: req.session?.user?.id,
|
|
},
|
|
select: {
|
|
id: true,
|
|
},
|
|
});
|
|
|
|
const data = {
|
|
type: "apple_calendar",
|
|
key: symmetricEncrypt(JSON.stringify({ username, password }), process.env.CALENDSO_ENCRYPTION_KEY!),
|
|
userId: user.id,
|
|
appId: "apple-calendar",
|
|
};
|
|
|
|
try {
|
|
const dav = new CalendarService({
|
|
id: 0,
|
|
...data,
|
|
});
|
|
await dav?.listCalendars();
|
|
await prisma.credential.create({
|
|
data,
|
|
});
|
|
} catch (reason) {
|
|
logger.error("Could not add this caldav account", reason);
|
|
return res.status(500).json({ message: "Could not add this caldav account" });
|
|
}
|
|
|
|
return res.status(200).json({ url: "/apps/installed" });
|
|
}
|
|
|
|
if (req.method === "GET") {
|
|
return res.status(200).json({ url: "/apps/apple-calendar/setup" });
|
|
}
|
|
}
|