This reverts commit d294a74aad.
This commit is contained in:
1 parent
bdf94c7f48
commit
6272c881c8
39 files changed
+240
-952
No files matched your search
@@ -1,29 +0,0 @@
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import monitorCallbackAsync from "@calcom/core/sentryWrapper";
|
||||
|
||||
import { getServerErrorFromUnknown } from "./getServerErrorFromUnknown";
|
||||
|
||||
type Handle<T> = (req: NextRequest) => Promise<T>;
|
||||
|
||||
/** Variant to use in App Router API routes. Allows us to get type inference from API handler responses */
|
||||
export const defaultResponder =
|
||||
<T>(f: Handle<T>) =>
|
||||
async (req: NextRequest) => {
|
||||
try {
|
||||
const result = await monitorCallbackAsync(f, req);
|
||||
if (result) {
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
} catch (err) {
|
||||
const error = getServerErrorFromUnknown(err);
|
||||
// we don't want to report Bad Request errors to Sentry / console
|
||||
if (!(error.statusCode >= 400 && error.statusCode < 500)) {
|
||||
console.error(err);
|
||||
const captureException = (await import("@sentry/nextjs")).captureException;
|
||||
captureException(err);
|
||||
}
|
||||
return NextResponse.json({ message: error.message, url: error.url, method: error.method });
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { Credentials } from "google-auth-library";
|
||||
|
||||
import { CredentialRepository } from "./credential";
|
||||
@@ -30,15 +29,6 @@ export class GoogleRepository {
|
||||
});
|
||||
}
|
||||
|
||||
static async upsertSelectedCalendar(
|
||||
data: Omit<Prisma.SelectedCalendarUncheckedCreateInput, "integration">
|
||||
) {
|
||||
return await SelectedCalendarRepository.upsert({
|
||||
...data,
|
||||
integration: "google_calendar",
|
||||
});
|
||||
}
|
||||
|
||||
static async findGoogleMeetCredential({ userId }: { userId: number }) {
|
||||
return await CredentialRepository.findFirstByUserIdAndType({
|
||||
userId,
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
type SelectedCalendarCreateInput = {
|
||||
credentialId: number;
|
||||
@@ -18,108 +15,4 @@ export class SelectedCalendarRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
static async upsert(data: Prisma.SelectedCalendarUncheckedCreateInput) {
|
||||
return await prisma.selectedCalendar.upsert({
|
||||
where: {
|
||||
userId_integration_externalId: {
|
||||
userId: data.userId,
|
||||
integration: data.integration,
|
||||
externalId: data.externalId,
|
||||
},
|
||||
},
|
||||
create: { ...data },
|
||||
update: { ...data },
|
||||
});
|
||||
}
|
||||
/** Retrieve calendars that need to be watched */
|
||||
static async getNextBatchToWatch(limit = 100) {
|
||||
// Get selected calendars from users that belong to a team that has calendar cache enabled
|
||||
const oneDayInMS = 24 * 60 * 60 * 1000;
|
||||
const tomorrowTimestamp = String(new Date().getTime() + oneDayInMS);
|
||||
const nextBatch = await prisma.selectedCalendar.findMany({
|
||||
take: limit,
|
||||
where: {
|
||||
user: {
|
||||
teams: {
|
||||
some: {
|
||||
team: {
|
||||
features: {
|
||||
some: {
|
||||
featureId: "calendar-cache",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// RN we only support google calendar subscriptions for now
|
||||
integration: "google_calendar",
|
||||
OR: [
|
||||
// Either is a calendar pending to be watched
|
||||
{ googleChannelExpiration: null },
|
||||
// Or is a calendar that is about to expire
|
||||
{ googleChannelExpiration: { lt: tomorrowTimestamp } },
|
||||
],
|
||||
},
|
||||
});
|
||||
return nextBatch;
|
||||
}
|
||||
/** Retrieve calendars that are being watched but shouldn't be anymore */
|
||||
static async getNextBatchToUnwatch(limit = 100) {
|
||||
const nextBatch = await prisma.selectedCalendar.findMany({
|
||||
take: limit,
|
||||
where: {
|
||||
user: {
|
||||
teams: {
|
||||
every: {
|
||||
team: {
|
||||
features: {
|
||||
none: {
|
||||
featureId: "calendar-cache",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// RN we only support google calendar subscriptions for now
|
||||
integration: "google_calendar",
|
||||
googleChannelExpiration: { not: null },
|
||||
},
|
||||
});
|
||||
return nextBatch;
|
||||
}
|
||||
static async delete(data: Prisma.SelectedCalendarUncheckedCreateInput) {
|
||||
return await prisma.selectedCalendar.delete({
|
||||
where: {
|
||||
userId_integration_externalId: {
|
||||
userId: data.userId,
|
||||
externalId: data.externalId,
|
||||
integration: data.integration,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
static async findMany(args: Prisma.SelectedCalendarFindManyArgs) {
|
||||
return await prisma.selectedCalendar.findMany(args);
|
||||
}
|
||||
static async findByGoogleChannelId(googleChannelId: string) {
|
||||
return await prisma.selectedCalendar.findUnique({
|
||||
where: {
|
||||
googleChannelId,
|
||||
},
|
||||
select: {
|
||||
credential: {
|
||||
select: {
|
||||
...credentialForCalendarServiceSelect,
|
||||
selectedCalendars: {
|
||||
orderBy: {
|
||||
externalId: "asc",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import prisma from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import type { User as UserType } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { UpId, UserProfile } from "@calcom/types/UserProfile";
|
||||
|
||||
@@ -748,19 +747,4 @@ export class UserRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
static async findUserWithCredentials({ id }: { id: number }) {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: {
|
||||
credentials: {
|
||||
select: credentialForCalendarServiceSelect,
|
||||
},
|
||||
timeZone: true,
|
||||
id: true,
|
||||
selectedCalendars: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user