Skip to content

Commit cbc8d3d

Browse files
Add DI for BookingAudit (calcom#25123)
1 parent e6ba899 commit cbc8d3d

26 files changed

Lines changed: 394 additions & 33 deletions

apps/api/v2/src/lib/modules/regular-booking.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { PrismaFeaturesRepository } from "@/lib/repositories/prisma-features.rep
44
import { PrismaHostRepository } from "@/lib/repositories/prisma-host.repository";
55
import { PrismaOOORepository } from "@/lib/repositories/prisma-ooo.repository";
66
import { PrismaUserRepository } from "@/lib/repositories/prisma-user.repository";
7+
import { Logger } from "@/lib/logger.bridge";
8+
import { BookingEventHandlerService } from "@/lib/services/booking-event-handler.service";
79
import { CheckBookingAndDurationLimitsService } from "@/lib/services/check-booking-and-duration-limits.service";
810
import { CheckBookingLimitsService } from "@/lib/services/check-booking-limits.service";
911
import { HashedLinkService } from "@/lib/services/hashed-link.service";
@@ -21,6 +23,13 @@ import { Module } from "@nestjs/common";
2123
PrismaHostRepository,
2224
PrismaOOORepository,
2325
PrismaUserRepository,
26+
{
27+
provide: Logger,
28+
useFactory: () => {
29+
return new Logger();
30+
},
31+
},
32+
BookingEventHandlerService,
2433
CheckBookingAndDurationLimitsService,
2534
CheckBookingLimitsService,
2635
HashedLinkService,

apps/api/v2/src/lib/services/booking-cancel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
22
import { Injectable } from "@nestjs/common";
33

4-
import { BookingCancelService as BaseBookingCancelService } from "@calcom/features/bookings/lib/handleCancelBooking";
4+
import { BookingCancelService as BaseBookingCancelService } from "@calcom/platform-libraries/bookings";
55

66
@Injectable()
77
export class BookingCancelService extends BaseBookingCancelService {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Injectable } from "@nestjs/common";
2+
3+
import { BookingEventHandlerService as BaseBookingEventHandlerService } from "@calcom/platform-libraries/bookings";
4+
5+
import { Logger } from "@/lib/logger.bridge";
6+
7+
import { HashedLinkService } from "./hashed-link.service";
8+
9+
@Injectable()
10+
export class BookingEventHandlerService extends BaseBookingEventHandlerService {
11+
constructor(hashedLinkService: HashedLinkService, bridgeLogger: Logger) {
12+
super({
13+
log: bridgeLogger,
14+
hashedLinkService,
15+
});
16+
}
17+
}
18+

apps/api/v2/src/lib/services/regular-booking.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PrismaBookingRepository } from "@/lib/repositories/prisma-booking.repository";
22
import { PrismaUserRepository } from "@/lib/repositories/prisma-user.repository";
3+
import { BookingEventHandlerService } from "@/lib/services/booking-event-handler.service";
34
import { CheckBookingAndDurationLimitsService } from "@/lib/services/check-booking-and-duration-limits.service";
45
import { HashedLinkService } from "@/lib/services/hashed-link.service";
56
import { LuckyUserService } from "@/lib/services/lucky-user.service";
@@ -17,7 +18,8 @@ export class RegularBookingService extends BaseRegularBookingService {
1718
bookingRepository: PrismaBookingRepository,
1819
hashedLinkService: HashedLinkService,
1920
luckyUserService: LuckyUserService,
20-
userRepository: PrismaUserRepository
21+
userRepository: PrismaUserRepository,
22+
bookingEventHandler: BookingEventHandlerService
2123
) {
2224
super({
2325
checkBookingAndDurationLimitsService,
@@ -26,6 +28,7 @@ export class RegularBookingService extends BaseRegularBookingService {
2628
hashedLinkService,
2729
luckyUserService,
2830
userRepository,
31+
bookingEventHandler,
2932
});
3033
}
3134
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { PrismaAuditActorRepository } from "@calcom/features/booking-audit/lib/repository/PrismaAuditActorRepository";
2+
import { BOOKING_AUDIT_DI_TOKENS } from "@calcom/features/booking-audit/di/tokens";
3+
import { bindModuleToClassOnToken } from "@calcom/features/di/di";
4+
import { moduleLoader as prismaModuleLoader } from "@calcom/features/di/modules/Prisma";
5+
import { createModule } from "../../di/di";
6+
7+
export const actorRepositoryModule = createModule();
8+
const token = BOOKING_AUDIT_DI_TOKENS.ACTOR_REPOSITORY;
9+
const moduleToken = BOOKING_AUDIT_DI_TOKENS.ACTOR_REPOSITORY_MODULE;
10+
const loadModule = bindModuleToClassOnToken({
11+
module: actorRepositoryModule,
12+
moduleToken,
13+
token,
14+
classs: PrismaAuditActorRepository,
15+
depsMap: {
16+
prismaClient: prismaModuleLoader,
17+
},
18+
});
19+
20+
export const moduleLoader = {
21+
token,
22+
loadModule,
23+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { PrismaBookingAuditRepository } from "@calcom/features/booking-audit/lib/repository/PrismaBookingAuditRepository";
2+
import { BOOKING_AUDIT_DI_TOKENS } from "@calcom/features/booking-audit/di/tokens";
3+
import { bindModuleToClassOnToken } from "@calcom/features/di/di";
4+
import { moduleLoader as prismaModuleLoader } from "@calcom/features/di/modules/Prisma";
5+
import { createModule } from "../../di/di";
6+
7+
export const bookingAuditRepositoryModule = createModule();
8+
const token = BOOKING_AUDIT_DI_TOKENS.BOOKING_AUDIT_REPOSITORY;
9+
const moduleToken = BOOKING_AUDIT_DI_TOKENS.BOOKING_AUDIT_REPOSITORY_MODULE;
10+
const loadModule = bindModuleToClassOnToken({
11+
module: bookingAuditRepositoryModule,
12+
moduleToken,
13+
token,
14+
classs: PrismaBookingAuditRepository,
15+
depsMap: {
16+
prismaClient: prismaModuleLoader,
17+
},
18+
});
19+
20+
export const moduleLoader = {
21+
token,
22+
loadModule,
23+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { BookingAuditService } from "@calcom/features/booking-audit/lib/service/BookingAuditService";
2+
import { BOOKING_AUDIT_DI_TOKENS } from "@calcom/features/booking-audit/di/tokens";
3+
import { moduleLoader as bookingAuditRepositoryModuleLoader } from "@calcom/features/booking-audit/di/BookingAuditRepository.module";
4+
import { moduleLoader as actorRepositoryModuleLoader } from "@calcom/features/booking-audit/di/ActorRepository.module";
5+
6+
import { createModule, bindModuleToClassOnToken } from "../../di/di";
7+
8+
export const bookingAuditServiceModule = createModule();
9+
const token = BOOKING_AUDIT_DI_TOKENS.BOOKING_AUDIT_SERVICE;
10+
const moduleToken = BOOKING_AUDIT_DI_TOKENS.BOOKING_AUDIT_SERVICE_MODULE;
11+
12+
const loadModule = bindModuleToClassOnToken({
13+
module: bookingAuditServiceModule,
14+
moduleToken,
15+
token,
16+
classs: BookingAuditService,
17+
depsMap: {
18+
bookingAuditRepository: bookingAuditRepositoryModuleLoader,
19+
actorRepository: actorRepositoryModuleLoader,
20+
},
21+
});
22+
23+
export const moduleLoader = {
24+
token,
25+
loadModule
26+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const BOOKING_AUDIT_DI_TOKENS = {
2+
BOOKING_AUDIT_SERVICE: Symbol("BookingAuditService"),
3+
BOOKING_AUDIT_SERVICE_MODULE: Symbol("BookingAuditServiceModule"),
4+
BOOKING_AUDIT_REPOSITORY: Symbol("BookingAuditRepository"),
5+
BOOKING_AUDIT_REPOSITORY_MODULE: Symbol("BookingAuditRepositoryModule"),
6+
ACTOR_REPOSITORY: Symbol("ActorRepository"),
7+
ACTOR_REPOSITORY_MODULE: Symbol("ActorRepositoryModule"),
8+
};

packages/features/booking-audit/lib/repository/IAuditActorRepository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ type AuditActor = {
1313
export interface IAuditActorRepository {
1414
findByUserUuid(userUuid: string): Promise<AuditActor | null>;
1515
findSystemActorOrThrow(): Promise<AuditActor>;
16+
// TODO: To be implemented in followup PR
17+
// upsertUserActor(userUuid: string): Promise<AuditActor>;
18+
// upsertGuestActor(email: string, name?: string, phone?: string): Promise<AuditActor>;
19+
// findByAttendeeId(attendeeId: number): Promise<AuditActor | null>;
1620
}
1721

packages/features/booking-audit/lib/repository/IBookingAuditRepository.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { JsonValue } from "@calcom/types/Json";
2+
13
export type BookingAuditType = "RECORD_CREATED" | "RECORD_UPDATED" | "RECORD_DELETED"
2-
export type BookingAuditAction = "CREATED" | "CANCELLED" | "ACCEPTED" | "REJECTED" | "PENDING" | "AWAITING_HOST" | "RESCHEDULED" | "ATTENDEE_ADDED" | "ATTENDEE_REMOVED" | "CANCELLATION_REASON_UPDATED" | "REJECTION_REASON_UPDATED" | "ASSIGNMENT_REASON_UPDATED" | "REASSIGNMENT_REASON_UPDATED" | "LOCATION_CHANGED" | "HOST_NO_SHOW_UPDATED" | "ATTENDEE_NO_SHOW_UPDATED" | "RESCHEDULE_REQUESTED"
4+
export type BookingAuditAction = "CREATED" | "CANCELLED" | "ACCEPTED" | "REJECTED" | "PENDING" | "AWAITING_HOST" | "RESCHEDULED" | "ATTENDEE_ADDED" | "ATTENDEE_REMOVED" | "REASSIGNMENT" | "LOCATION_CHANGED" | "HOST_NO_SHOW_UPDATED" | "ATTENDEE_NO_SHOW_UPDATED" | "RESCHEDULE_REQUESTED"
35
export type BookingAuditCreateInput = {
46
bookingUid: string;
57
actorId: string;
68
action: BookingAuditAction;
7-
data: unknown;
8-
createdAt: Date;
9+
data: JsonValue;
910
type: BookingAuditType;
1011
timestamp: Date;
1112
}
@@ -14,9 +15,12 @@ type BookingAudit = {
1415
id: string;
1516
bookingUid: string;
1617
actorId: string;
17-
action: string;
18-
data: unknown;
18+
action: BookingAuditAction;
19+
type: BookingAuditType;
20+
timestamp: Date;
1921
createdAt: Date;
22+
updatedAt: Date;
23+
data: JsonValue;
2024
}
2125

2226
export interface IBookingAuditRepository {

0 commit comments

Comments
 (0)