mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs) Format small subdirectories in packages/features: di, flags, holidays, oauth, settings, users, assignment-reason, selectedCalendar, hashedLink, host, form, form-builder, availability, data-table, pbac, schedules, troubleshooter, eventtypes, calendar-subscription, and root-level files. Also includes straggler apps/web BookEventForm.tsx. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: apply biome formatting to packages/features (batch 2 - medium subdirs) Format medium subdirectories in packages/features: auth, credentials, calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone, tasker, and webhooks. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: apply biome formatting to packages/features (batch 3 - bookings + insights) Format bookings and insights subdirectories in packages/features. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: apply biome formatting to packages/features (batch 4 - ee) Format packages/features/ee subdirectory covering billing, workflows, organizations, teams, managed-event-types, round-robin, dsync, integration-attribute-sync, and payments. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1) Format booking-audit di, actions, common, dto, repository, and types subdirectories in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2) Format booking-audit service subdirectory in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
217 lines
4.7 KiB
TypeScript
217 lines
4.7 KiB
TypeScript
import { prisma } from "@calcom/prisma";
|
|
import type { Prisma } from "@calcom/prisma/client";
|
|
import { BookingStatus } from "@calcom/prisma/enums";
|
|
|
|
const holidayCacheSelect = {
|
|
id: true,
|
|
countryCode: true,
|
|
calendarId: true,
|
|
eventId: true,
|
|
name: true,
|
|
date: true,
|
|
year: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
} satisfies Prisma.HolidayCacheSelect;
|
|
|
|
const userHolidaySettingsSelect = {
|
|
id: true,
|
|
userId: true,
|
|
countryCode: true,
|
|
disabledIds: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
} satisfies Prisma.UserHolidaySettingsSelect;
|
|
|
|
export class HolidayRepository {
|
|
static async findFirstCacheEntry({ countryCode, year }: { countryCode: string; year: number }) {
|
|
return prisma.holidayCache.findFirst({
|
|
where: {
|
|
countryCode,
|
|
year,
|
|
},
|
|
orderBy: {
|
|
updatedAt: "desc",
|
|
},
|
|
select: holidayCacheSelect,
|
|
});
|
|
}
|
|
|
|
static async findManyCachedHolidays({ countryCode, year }: { countryCode: string; year: number }) {
|
|
return prisma.holidayCache.findMany({
|
|
where: {
|
|
countryCode,
|
|
year,
|
|
},
|
|
orderBy: {
|
|
date: "asc",
|
|
},
|
|
select: holidayCacheSelect,
|
|
});
|
|
}
|
|
|
|
static async findCachedHolidaysInRange({
|
|
countryCode,
|
|
startDate,
|
|
endDate,
|
|
}: {
|
|
countryCode: string;
|
|
startDate: Date;
|
|
endDate: Date;
|
|
}) {
|
|
return prisma.holidayCache.findMany({
|
|
where: {
|
|
countryCode,
|
|
date: {
|
|
gte: startDate,
|
|
lte: endDate,
|
|
},
|
|
},
|
|
orderBy: {
|
|
date: "asc",
|
|
},
|
|
select: holidayCacheSelect,
|
|
});
|
|
}
|
|
|
|
static async deleteManyCacheEntries({ countryCode, year }: { countryCode: string; year: number }) {
|
|
return prisma.holidayCache.deleteMany({
|
|
where: {
|
|
countryCode,
|
|
year,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async createManyCacheEntries(data: Prisma.HolidayCacheCreateManyInput[]) {
|
|
return prisma.holidayCache.createMany({
|
|
data,
|
|
skipDuplicates: true,
|
|
});
|
|
}
|
|
|
|
static async refreshCache({
|
|
countryCode,
|
|
year,
|
|
holidays,
|
|
}: {
|
|
countryCode: string;
|
|
year: number;
|
|
holidays: Prisma.HolidayCacheCreateManyInput[];
|
|
}) {
|
|
return prisma.$transaction(async (tx) => {
|
|
await tx.holidayCache.deleteMany({
|
|
where: {
|
|
countryCode,
|
|
year,
|
|
},
|
|
});
|
|
|
|
if (holidays.length > 0) {
|
|
await tx.holidayCache.createMany({
|
|
data: holidays,
|
|
skipDuplicates: true,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
static async findUserSettings({ userId }: { userId: number }) {
|
|
return prisma.userHolidaySettings.findUnique({
|
|
where: { userId },
|
|
select: userHolidaySettingsSelect,
|
|
});
|
|
}
|
|
|
|
static async findUserSettingsSelect<T extends Prisma.UserHolidaySettingsSelect>({
|
|
userId,
|
|
select,
|
|
}: {
|
|
userId: number;
|
|
select: T;
|
|
}) {
|
|
return prisma.userHolidaySettings.findUnique({
|
|
where: { userId },
|
|
select,
|
|
});
|
|
}
|
|
|
|
static async upsertUserSettings({
|
|
userId,
|
|
countryCode,
|
|
disabledIds = [],
|
|
resetDisabledHolidays = false,
|
|
}: {
|
|
userId: number;
|
|
countryCode: string | null;
|
|
disabledIds?: string[];
|
|
resetDisabledHolidays?: boolean;
|
|
}) {
|
|
return prisma.userHolidaySettings.upsert({
|
|
where: { userId },
|
|
create: {
|
|
userId,
|
|
countryCode,
|
|
disabledIds,
|
|
},
|
|
update: {
|
|
countryCode,
|
|
...(resetDisabledHolidays ? { disabledIds: [] } : {}),
|
|
},
|
|
select: userHolidaySettingsSelect,
|
|
});
|
|
}
|
|
|
|
static async updateUserSettings({
|
|
userId,
|
|
data,
|
|
}: {
|
|
userId: number;
|
|
data: Prisma.UserHolidaySettingsUpdateInput;
|
|
}) {
|
|
return prisma.userHolidaySettings.update({
|
|
where: { userId },
|
|
data,
|
|
select: userHolidaySettingsSelect,
|
|
});
|
|
}
|
|
|
|
static async updateDisabledIds({ userId, disabledIds }: { userId: number; disabledIds: string[] }) {
|
|
return prisma.userHolidaySettings.update({
|
|
where: { userId },
|
|
data: { disabledIds },
|
|
select: userHolidaySettingsSelect,
|
|
});
|
|
}
|
|
|
|
static async findBookingsInDateRanges({
|
|
userId,
|
|
dateRanges,
|
|
}: {
|
|
userId: number;
|
|
dateRanges: Array<{ start: Date; end: Date }>;
|
|
}) {
|
|
if (dateRanges.length === 0) return [];
|
|
|
|
return prisma.booking.findMany({
|
|
where: {
|
|
userId,
|
|
status: { in: [BookingStatus.ACCEPTED, BookingStatus.PENDING] },
|
|
OR: dateRanges.map(({ start, end }) => ({
|
|
AND: [{ startTime: { lt: end } }, { endTime: { gt: start } }],
|
|
})),
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
startTime: true,
|
|
endTime: true,
|
|
attendees: {
|
|
take: 1,
|
|
select: { name: true },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|