diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index 9260b4ed83..cc4f68b293 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -38,7 +38,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.152", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.156", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts b/apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts index 828207d108..75a98e7a66 100644 --- a/apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts +++ b/apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts @@ -448,6 +448,7 @@ export class BookingsService_2024_08_13 { orgId: profile?.organizationId || null, emailsEnabled, platformClientParams, + reassignedById: requestUser.id, }); const reassigned = await this.bookingsRepository.getByUidWithUser(bookingUid); diff --git a/packages/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder.ts b/packages/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder.ts index 65e3976129..da6f918093 100644 --- a/packages/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder.ts +++ b/packages/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder.ts @@ -7,6 +7,11 @@ import { AssignmentReasonEnum } from "@calcom/prisma/enums"; const { getAttributesQueryValue } = acrossQueryValueCompatiblity; +export enum RRReassignmentType { + ROUND_ROBIN = "round_robin", + MANUAL = "manual", +} + export default class AssignmentReasonRecorder { static async routingFormRoute({ bookingId, @@ -143,10 +148,12 @@ export default class AssignmentReasonRecorder { bookingId, reassignById, reassignReason, + reassignmentType, }: { bookingId: number; reassignById: number; reassignReason?: string; + reassignmentType: RRReassignmentType; }) { const reassignedBy = await prisma.user.findFirst({ where: { @@ -164,7 +171,10 @@ export default class AssignmentReasonRecorder { await prisma.assignmentReason.create({ data: { bookingId: bookingId, - reasonEnum: AssignmentReasonEnum.REASSIGNED, + reasonEnum: + reassignmentType === RRReassignmentType.MANUAL + ? AssignmentReasonEnum.REASSIGNED + : AssignmentReasonEnum.RR_REASSIGNED, reasonString, }, }); diff --git a/packages/features/ee/round-robin/roundRobinManualReassignment.ts b/packages/features/ee/round-robin/roundRobinManualReassignment.ts index 4f3383e851..24d5de5779 100644 --- a/packages/features/ee/round-robin/roundRobinManualReassignment.ts +++ b/packages/features/ee/round-robin/roundRobinManualReassignment.ts @@ -11,7 +11,9 @@ import { import getBookingResponsesSchema from "@calcom/features/bookings/lib/getBookingResponsesSchema"; import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB"; -import AssignmentReasonRecorder from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder"; +import AssignmentReasonRecorder, { + RRReassignmentType, +} from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder"; import { scheduleEmailReminder, deleteScheduledEmailReminder, @@ -64,6 +66,8 @@ export const roundRobinManualReassignment = async ({ prefix: ["roundRobinManualReassign", `${bookingId}`], }); + roundRobinReassignLogger.info(`User ${reassignedById} initiating manual reassignment to user ${newUserId}`); + let booking = await prisma.booking.findUnique({ where: { id: bookingId }, select: bookingSelect, @@ -185,6 +189,7 @@ export const roundRobinManualReassignment = async ({ bookingId, reassignReason, reassignById: reassignedById, + reassignmentType: RRReassignmentType.MANUAL, }); } else if (currentRRHost) { // Update the round-robin host attendee diff --git a/packages/features/ee/round-robin/roundRobinReassignment.ts b/packages/features/ee/round-robin/roundRobinReassignment.ts index 304e2cf89c..8e00628e36 100644 --- a/packages/features/ee/round-robin/roundRobinReassignment.ts +++ b/packages/features/ee/round-robin/roundRobinReassignment.ts @@ -13,6 +13,9 @@ import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventR import { ensureAvailableUsers } from "@calcom/features/bookings/lib/handleNewBooking/ensureAvailableUsers"; import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB"; import type { IsFixedAwareUser } from "@calcom/features/bookings/lib/handleNewBooking/types"; +import AssignmentReasonRecorder, { + RRReassignmentType, +} from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder"; import { scheduleEmailReminder, deleteScheduledEmailReminder, @@ -47,16 +50,20 @@ export const roundRobinReassignment = async ({ orgId, emailsEnabled = true, platformClientParams, + reassignedById, }: { bookingId: number; orgId: number | null; emailsEnabled?: boolean; platformClientParams?: PlatformClientParams; + reassignedById: number; }) => { const roundRobinReassignLogger = logger.getSubLogger({ prefix: ["roundRobinReassign", `${bookingId}`], }); + roundRobinReassignLogger.info(`User ${reassignedById} initiating round robin reassignment`); + let booking = await prisma.booking.findUnique({ where: { id: bookingId, @@ -258,6 +265,14 @@ export const roundRobinReassignment = async ({ }); } + roundRobinReassignLogger.info(`Successfully reassigned to user ${reassignedRRHost.id}`); + + await AssignmentReasonRecorder.roundRobinReassignment({ + bookingId, + reassignById: reassignedById, + reassignmentType: RRReassignmentType.ROUND_ROBIN, + }); + const destinationCalendar = await getDestinationCalendar({ eventType, booking, diff --git a/packages/prisma/migrations/20250209012421_add_rr_reassign_reason/migration.sql b/packages/prisma/migrations/20250209012421_add_rr_reassign_reason/migration.sql new file mode 100644 index 0000000000..39e9b76980 --- /dev/null +++ b/packages/prisma/migrations/20250209012421_add_rr_reassign_reason/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "AssignmentReasonEnum" ADD VALUE 'RR_REASSIGNED'; diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index bf7f645bdf..716d68ed5b 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -1784,6 +1784,7 @@ enum AssignmentReasonEnum { ROUTING_FORM_ROUTING ROUTING_FORM_ROUTING_FALLBACK REASSIGNED + RR_REASSIGNED REROUTED SALESFORCE_ASSIGNMENT } diff --git a/packages/trpc/server/routers/viewer/teams/roundRobin/roundRobinReassign.handler.ts b/packages/trpc/server/routers/viewer/teams/roundRobin/roundRobinReassign.handler.ts index 856bdc6ed5..75ff43465d 100644 --- a/packages/trpc/server/routers/viewer/teams/roundRobin/roundRobinReassign.handler.ts +++ b/packages/trpc/server/routers/viewer/teams/roundRobin/roundRobinReassign.handler.ts @@ -23,7 +23,11 @@ export const roundRobinReassignHandler = async ({ ctx, input }: RoundRobinReassi throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" }); } - return await roundRobinReassignment({ bookingId, orgId: ctx.user.organizationId }); + return await roundRobinReassignment({ + bookingId, + orgId: ctx.user.organizationId, + reassignedById: ctx.user.id, + }); }; export default roundRobinReassignHandler;