mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +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]>
126 lines
3.3 KiB
TypeScript
126 lines
3.3 KiB
TypeScript
import type { PrismaClient } from "@calcom/prisma";
|
|
import type { Prisma } from "@calcom/prisma/client";
|
|
|
|
import type {
|
|
IBookingAuditRepository,
|
|
BookingAuditCreateInput,
|
|
BookingAuditWithActor,
|
|
} from "./IBookingAuditRepository";
|
|
import { BookingAuditContextSchema } from "../dto/types";
|
|
|
|
type Dependencies = {
|
|
prismaClient: PrismaClient;
|
|
};
|
|
|
|
/**
|
|
* Safe actor fields to expose in audit logs
|
|
* Excludes PII fields like email and phone that aren't needed for display
|
|
*/
|
|
const safeActorSelect = {
|
|
id: true,
|
|
type: true,
|
|
userUuid: true,
|
|
attendeeId: true,
|
|
credentialId: true,
|
|
name: true,
|
|
createdAt: true,
|
|
} as const;
|
|
|
|
const safeBookingAuditSelect = {
|
|
id: true,
|
|
bookingUid: true,
|
|
actorId: true,
|
|
action: true,
|
|
type: true,
|
|
timestamp: true,
|
|
source: true,
|
|
operationId: true,
|
|
data: true,
|
|
context: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
} as const;
|
|
|
|
export class PrismaBookingAuditRepository implements IBookingAuditRepository {
|
|
constructor(private readonly deps: Dependencies) {}
|
|
|
|
private parsed<T extends { context: Prisma.JsonValue }>(auditLog: T) {
|
|
return {
|
|
...auditLog,
|
|
context: auditLog.context ? BookingAuditContextSchema.parse(auditLog.context) : null,
|
|
};
|
|
}
|
|
|
|
async create(bookingAudit: BookingAuditCreateInput) {
|
|
const created = await this.deps.prismaClient.bookingAudit.create({
|
|
data: {
|
|
bookingUid: bookingAudit.bookingUid,
|
|
actorId: bookingAudit.actorId,
|
|
action: bookingAudit.action,
|
|
type: bookingAudit.type,
|
|
timestamp: bookingAudit.timestamp,
|
|
source: bookingAudit.source,
|
|
operationId: bookingAudit.operationId,
|
|
data: bookingAudit.data === null ? undefined : bookingAudit.data,
|
|
context: bookingAudit.context ?? undefined,
|
|
},
|
|
});
|
|
|
|
return this.parsed(created);
|
|
}
|
|
|
|
async createMany(bookingAudits: BookingAuditCreateInput[]) {
|
|
const result = await this.deps.prismaClient.bookingAudit.createMany({
|
|
data: bookingAudits.map((bookingAudit) => ({
|
|
bookingUid: bookingAudit.bookingUid,
|
|
actorId: bookingAudit.actorId,
|
|
action: bookingAudit.action,
|
|
type: bookingAudit.type,
|
|
timestamp: bookingAudit.timestamp,
|
|
source: bookingAudit.source,
|
|
operationId: bookingAudit.operationId,
|
|
data: bookingAudit.data === null ? undefined : bookingAudit.data,
|
|
context: bookingAudit.context === undefined ? undefined : bookingAudit.context,
|
|
})),
|
|
});
|
|
return { count: result.count };
|
|
}
|
|
|
|
async findAllForBooking(bookingUid: string): Promise<BookingAuditWithActor[]> {
|
|
const results = await this.deps.prismaClient.bookingAudit.findMany({
|
|
where: {
|
|
bookingUid,
|
|
},
|
|
select: {
|
|
...safeBookingAuditSelect,
|
|
actor: {
|
|
select: safeActorSelect,
|
|
},
|
|
},
|
|
orderBy: {
|
|
timestamp: "desc",
|
|
},
|
|
});
|
|
|
|
return results.map(this.parsed);
|
|
}
|
|
|
|
async findRescheduledLogsOfBooking(bookingUid: string): Promise<BookingAuditWithActor[]> {
|
|
const results = await this.deps.prismaClient.bookingAudit.findMany({
|
|
where: {
|
|
bookingUid,
|
|
action: "RESCHEDULED",
|
|
},
|
|
select: {
|
|
...safeBookingAuditSelect,
|
|
actor: {
|
|
select: safeActorSelect,
|
|
},
|
|
},
|
|
orderBy: { timestamp: "desc" },
|
|
});
|
|
|
|
return results.map(this.parsed);
|
|
}
|
|
}
|