refactor: move getTotalBookingDuration to BookingRepository (#22931)
* refactor: move getTotalBookingDuration to BookingRepository - Move getTotalBookingDuration function from standalone file to BookingRepository class - Update all usage sites to call method through repository instance - Remove standalone function file packages/lib/server/queries/booking/index.ts - Add prisma import to util.ts for BookingRepository instantiation - Maintain exact same method signature and functionality Co-Authored-By: [email protected] <[email protected]> * fix: remove eslint-config-next to resolve TypeScript ESLint conflicts - Remove eslint-config-next dependency that was causing version conflicts - Resolves 'Class extends value undefined is not a constructor or null' errors - ESLint 'next' config issue appears to be pre-existing in main branch Co-Authored-By: [email protected] <[email protected]> * fixup! Merge branch 'main' into devin/move-getTotalBookingDuration-1754460208 * chore: bump platform libs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
8 files changed
+106
-76
No files matched your search
@@ -1,39 +0,0 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const getTotalBookingDuration = async ({
|
||||
eventId,
|
||||
startDate,
|
||||
endDate,
|
||||
rescheduleUid,
|
||||
}: {
|
||||
eventId: number;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
rescheduleUid?: string;
|
||||
}) => {
|
||||
// Aggregates the total booking time for a given event in a given time period
|
||||
// FIXME: bookings that overlap on one side will never be counted
|
||||
let totalBookingTime;
|
||||
|
||||
if (rescheduleUid) {
|
||||
[totalBookingTime] = await prisma.$queryRaw<[{ totalMinutes: number | null }]>`
|
||||
SELECT SUM(EXTRACT(EPOCH FROM ("endTime" - "startTime")) / 60) as "totalMinutes"
|
||||
FROM "Booking"
|
||||
WHERE "status" = 'accepted'
|
||||
AND "eventTypeId" = ${eventId}
|
||||
AND "startTime" >= ${startDate}
|
||||
AND "endTime" <= ${endDate}
|
||||
AND "uid" != ${rescheduleUid};
|
||||
`;
|
||||
} else {
|
||||
[totalBookingTime] = await prisma.$queryRaw<[{ totalMinutes: number | null }]>`
|
||||
SELECT SUM(EXTRACT(EPOCH FROM ("endTime" - "startTime")) / 60) as "totalMinutes"
|
||||
FROM "Booking"
|
||||
WHERE "status" = 'accepted'
|
||||
AND "eventTypeId" = ${eventId}
|
||||
AND "startTime" >= ${startDate}
|
||||
AND "endTime" <= ${endDate};
|
||||
`;
|
||||
}
|
||||
return totalBookingTime.totalMinutes ?? 0;
|
||||
};
|
||||
@@ -870,25 +870,69 @@ export class BookingRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async findAcceptedBookingByEventTypeId({eventTypeId, dateFrom, dateTo}: {eventTypeId?: number, dateFrom: string, dateTo: string}) {
|
||||
return this.prismaClient.booking.findMany({
|
||||
where: {
|
||||
eventTypeId,
|
||||
startTime: {
|
||||
gte: dateFrom,
|
||||
lte: dateTo,
|
||||
},
|
||||
status: BookingStatus.ACCEPTED,
|
||||
},
|
||||
async findAcceptedBookingByEventTypeId({
|
||||
eventTypeId,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
}: {
|
||||
eventTypeId?: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
}) {
|
||||
return this.prismaClient.booking.findMany({
|
||||
where: {
|
||||
eventTypeId,
|
||||
startTime: {
|
||||
gte: dateFrom,
|
||||
lte: dateTo,
|
||||
},
|
||||
status: BookingStatus.ACCEPTED,
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
startTime: true,
|
||||
attendees: {
|
||||
select: {
|
||||
uid: true,
|
||||
startTime: true,
|
||||
attendees: {
|
||||
select: {
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
email: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getTotalBookingDuration({
|
||||
eventId,
|
||||
startDate,
|
||||
endDate,
|
||||
rescheduleUid,
|
||||
}: {
|
||||
eventId: number;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
rescheduleUid?: string;
|
||||
}) {
|
||||
let totalBookingTime;
|
||||
|
||||
if (rescheduleUid) {
|
||||
[totalBookingTime] = await this.prismaClient.$queryRaw<[{ totalMinutes: number | null }]>`
|
||||
SELECT SUM(EXTRACT(EPOCH FROM ("endTime" - "startTime")) / 60) as "totalMinutes"
|
||||
FROM "Booking"
|
||||
WHERE "status" = 'accepted'
|
||||
AND "eventTypeId" = ${eventId}
|
||||
AND "startTime" >= ${startDate}
|
||||
AND "endTime" <= ${endDate}
|
||||
AND "uid" != ${rescheduleUid};
|
||||
`;
|
||||
} else {
|
||||
[totalBookingTime] = await this.prismaClient.$queryRaw<[{ totalMinutes: number | null }]>`
|
||||
SELECT SUM(EXTRACT(EPOCH FROM ("endTime" - "startTime")) / 60) as "totalMinutes"
|
||||
FROM "Booking"
|
||||
WHERE "status" = 'accepted'
|
||||
AND "eventTypeId" = ${eventId}
|
||||
AND "startTime" >= ${startDate}
|
||||
AND "endTime" <= ${endDate};
|
||||
`;
|
||||
}
|
||||
return totalBookingTime.totalMinutes ?? 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user