* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Update CalendarService.ts * Type fixes * WIP * fix: improve cache hits * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Feedback * Update CalendarService.ts * Update CalendarService.ts * Update _router.ts * feedback * WIP * WIP * Update schema.prisma * feedback * typefixes * Update Calendar.d.ts * fix: watches when adding a calendar * Discard changes to packages/app-store/googlecalendar/api/add.ts * WIP Signed-off-by: Omar López <[email protected]> * WIP Signed-off-by: Omar López <[email protected]> * WP Signed-off-by: Omar López <[email protected]> * Update calendar.ts * Update calendar.ts * Update callback.ts * Update callback.ts * Conflicts * WIP * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/features/settings/layouts/SettingsLayout.tsx * Update calendar-cache.repository.ts * WIP * Update getSelectedCalendarsToWatch.sql * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/app-store/googlecalendar/lib/CalendarService.ts * Create CalendarService.wip.ts * WIP * Update CalendarService.ts * Update getSelectedCalendarsToWatch.sql * Delete CalendarService.wip.ts * test updates * cleanup Signed-off-by: Omar López <[email protected]> * Update CalendarService.test.ts * Update CalendarService.ts * type fixes * Update OAuthManager.ts * Update CalendarService.ts * Almost there * Update CalendarService.test.ts * Update calendar.ts * Update callback.ts * Update toggleFeatureFlag.handler.ts * fix: feedback * Update getSelectedCalendarsToWatch.sql * Fix unit tests --------- Signed-off-by: Omar López <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import type { NextApiRequest } from "next";
|
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
|
|
import { SelectedCalendarRepository } from "@calcom/lib/server/repository/selectedCalendar";
|
|
|
|
import { getCalendar } from "../../_utils/getCalendar";
|
|
|
|
async function postHandler(req: NextApiRequest) {
|
|
if (req.headers["x-goog-channel-token"] !== process.env.GOOGLE_WEBHOOK_TOKEN) {
|
|
throw new HttpError({ statusCode: 403, message: "Invalid API key" });
|
|
}
|
|
if (typeof req.headers["x-goog-channel-id"] !== "string") {
|
|
throw new HttpError({ statusCode: 403, message: "Missing Channel ID" });
|
|
}
|
|
|
|
const selectedCalendar = await SelectedCalendarRepository.findByGoogleChannelId(
|
|
req.headers["x-goog-channel-id"]
|
|
);
|
|
|
|
if (!selectedCalendar) {
|
|
throw new HttpError({
|
|
statusCode: 200,
|
|
message: `No selected calendar found for googleChannelId: ${req.headers["x-goog-channel-id"]}`,
|
|
});
|
|
}
|
|
const { credential } = selectedCalendar;
|
|
if (!credential)
|
|
throw new HttpError({
|
|
statusCode: 200,
|
|
message: `No credential found for selected calendar for googleChannelId: ${req.headers["x-goog-channel-id"]}`,
|
|
});
|
|
const { selectedCalendars } = credential;
|
|
const calendar = await getCalendar(credential);
|
|
await calendar?.fetchAvailabilityAndSetCache?.(selectedCalendars);
|
|
return { message: "ok" };
|
|
}
|
|
|
|
export default defaultHandler({
|
|
POST: Promise.resolve({ default: defaultResponder(postHandler) }),
|
|
});
|