2c8ff89fac
* wip * Filter only selectedCalendars where ff is enabled * test: fix and add tests for calendar subscription cache feature Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * test: fix SelectedCalendarRepository tests for new teamIds parameter Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import type { ISelectedCalendarRepository } from "@calcom/lib/server/repository/SelectedCalendarRepository.interface";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
import type { Prisma } from "@calcom/prisma/client";
|
|
|
|
export class SelectedCalendarRepository implements ISelectedCalendarRepository {
|
|
constructor(private prismaClient: PrismaClient) {}
|
|
|
|
async findById(id: string) {
|
|
return this.prismaClient.selectedCalendar.findUnique({
|
|
where: { id },
|
|
});
|
|
}
|
|
|
|
async findByChannelId(channelId: string) {
|
|
return this.prismaClient.selectedCalendar.findFirst({ where: { channelId } });
|
|
}
|
|
|
|
async findNextSubscriptionBatch({
|
|
take,
|
|
teamIds,
|
|
integrations,
|
|
}: {
|
|
take: number;
|
|
teamIds: number[];
|
|
integrations: string[];
|
|
}) {
|
|
return this.prismaClient.selectedCalendar.findMany({
|
|
where: {
|
|
integration: { in: integrations },
|
|
OR: [{ syncSubscribedAt: null }, { channelExpiration: { lte: new Date() } }],
|
|
user: {
|
|
teams: {
|
|
some: {
|
|
teamId: { in: teamIds },
|
|
accepted: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
take,
|
|
});
|
|
}
|
|
|
|
async updateSyncStatus(
|
|
id: string,
|
|
data: Pick<
|
|
Prisma.SelectedCalendarUpdateInput,
|
|
"syncToken" | "syncedAt" | "syncErrorAt" | "syncErrorCount"
|
|
>
|
|
) {
|
|
return this.prismaClient.selectedCalendar.update({
|
|
where: { id },
|
|
data,
|
|
});
|
|
}
|
|
|
|
async updateSubscription(
|
|
id: string,
|
|
data: Pick<
|
|
Prisma.SelectedCalendarUpdateInput,
|
|
| "channelId"
|
|
| "channelResourceId"
|
|
| "channelResourceUri"
|
|
| "channelKind"
|
|
| "channelExpiration"
|
|
| "syncSubscribedAt"
|
|
>
|
|
) {
|
|
return this.prismaClient.selectedCalendar.update({
|
|
where: { id },
|
|
data,
|
|
});
|
|
}
|
|
}
|