refactor: create PrismaOOORepository in /features/ooo (#25850)

* move to features

* update imports
This commit is contained in:
Benny Joo authored and GitHub committed 2025-12-14 08:39:58 -03:00
1 parent 68a8fade89
commit 972f983824
6 files changed
+8 -12

No files matched your search

@@ -11,6 +11,7 @@ import {
} from "@calcom/features/busyTimes/lib/getBusyTimesFromLimits";
import { getBusyTimesService } from "@calcom/features/di/containers/BusyTimes";
import { EventTypeRepository } from "@calcom/features/eventtypes/repositories/eventTypeRepository";
import type { PrismaOOORepository } from "@calcom/features/ooo/repositories/PrismaOOORepository";
import type { IRedisService } from "@calcom/features/redis/IRedisService";
import type { DateOverride, WorkingHours } from "@calcom/features/schedules/lib/date-ranges";
import { buildDateRanges, subtract } from "@calcom/features/schedules/lib/date-ranges";
@@ -24,7 +25,6 @@ import { getPeriodStartDatesBetween as getPeriodStartDatesBetweenUtil } from "@c
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { withReporting } from "@calcom/lib/sentryWrapper";
import type { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
import type {
Booking,
Prisma,
@@ -5,13 +5,13 @@ import dayjs from "@calcom/dayjs";
import type { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { getBusyCalendarTimes } from "@calcom/features/calendars/lib/CalendarManager";
import type { HostRepository } from "@calcom/features/host/repositories/HostRepository";
import type { PrismaOOORepository } from "@calcom/features/ooo/repositories/PrismaOOORepository";
import { mergeOverlappingRanges } from "@calcom/features/schedules/lib/date-ranges";
import type { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import logger from "@calcom/lib/logger";
import { raqbQueryValueSchema } from "@calcom/lib/raqb/zod";
import { safeStringify } from "@calcom/lib/safeStringify";
import type { PrismaAttributeRepository } from "@calcom/lib/server/repository/PrismaAttributeRepository";
import type { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
import type { Prisma } from "@calcom/prisma/client";
import type { User, Booking, SelectedCalendar } from "@calcom/prisma/client";
import type { AttributeType } from "@calcom/prisma/enums";
+2 -2
View File
@@ -1,6 +1,6 @@
import { DI_TOKENS } from "@calcom/features/di/tokens";
import { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
import { moduleLoader as prismaModuleLoader } from "@calcom/features/di/modules/Prisma";
import { DI_TOKENS } from "@calcom/features/di/tokens";
import { PrismaOOORepository } from "@calcom/features/ooo/repositories/PrismaOOORepository";
import { createModule, bindModuleToClassOnToken, type ModuleLoader } from "../di";
@@ -0,0 +1,182 @@
import type { PrismaClient } from "@calcom/prisma";
export class PrismaOOORepository {
constructor(private prismaClient: PrismaClient) {}
async findManyOOO({
startTimeDate,
endTimeDate,
allUserIds,
}: {
startTimeDate: Date;
endTimeDate: Date;
allUserIds: number[];
}) {
return this.prismaClient.outOfOfficeEntry.findMany({
where: {
userId: {
in: allUserIds,
},
OR: [
// outside of range
// (start <= 'dateTo' AND end >= 'dateFrom')
{
start: {
lte: endTimeDate,
},
end: {
gte: startTimeDate,
},
},
// start is between dateFrom and dateTo but end is outside of range
// (start <= 'dateTo' AND end >= 'dateTo')
{
start: {
lte: endTimeDate,
},
end: {
gte: endTimeDate,
},
},
// end is between dateFrom and dateTo but start is outside of range
// (start <= 'dateFrom' OR end <= 'dateTo')
{
start: {
lte: startTimeDate,
},
end: {
lte: endTimeDate,
},
},
],
},
select: {
id: true,
start: true,
end: true,
notes: true,
showNotePublicly: true,
user: {
select: {
id: true,
name: true,
},
},
toUser: {
select: {
id: true,
username: true,
name: true,
},
},
reason: {
select: {
id: true,
emoji: true,
reason: true,
},
},
},
});
}
async findUserOOODays({ userId, dateTo, dateFrom }: { userId: number; dateTo: string; dateFrom: string }) {
return this.prismaClient.outOfOfficeEntry.findMany({
where: {
userId,
OR: [
// outside of range
// (start <= 'dateTo' AND end >= 'dateFrom')
{
start: {
lte: dateTo,
},
end: {
gte: dateFrom,
},
},
// start is between dateFrom and dateTo but end is outside of range
// (start <= 'dateTo' AND end >= 'dateTo')
{
start: {
lte: dateTo,
},
end: {
gte: dateTo,
},
},
// end is between dateFrom and dateTo but start is outside of range
// (start <= 'dateFrom' OR end <= 'dateTo')
{
start: {
lte: dateFrom,
},
end: {
lte: dateTo,
},
},
],
},
select: {
id: true,
start: true,
end: true,
notes: true,
showNotePublicly: true,
user: {
select: {
id: true,
name: true,
},
},
toUser: {
select: {
id: true,
username: true,
name: true,
},
},
reason: {
select: {
id: true,
emoji: true,
reason: true,
},
},
},
});
}
async findOOOEntriesInInterval({
userIds,
startDate,
endDate,
}: {
userIds: number[];
startDate: Date;
endDate: Date;
}) {
return this.prismaClient.outOfOfficeEntry.findMany({
where: {
userId: {
in: userIds,
},
start: {
lte: endDate,
},
end: {
gte: startDate,
},
},
select: {
start: true,
end: true,
userId: true,
},
});
}
}