fix: Add assignment reason for round robin reassignments (#19199)

* Add `RR_REASSIGNED` to schema

* Handle recording reassigned manual vs rr

* Pass manual assignment prop to `AssignmentReasonRecorder`

* Add log to determine who is doing the reassignment

* RR reassign - add initializing log

* Record assignment reason when reassigning via rr

* Add `reassignedById` in trpc endpoint

* Add `reassignedById` param in api v2 endpoint

* Migration to add `RR_REASSIGNED`
This commit is contained in:
Joe Au-Yeung
2025-03-26 10:39:16 -03:00
committed by GitHub
parent e215786afb
commit 122af4538d
8 changed files with 42 additions and 4 deletions
+1 -1
View File
@@ -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": "*",
@@ -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);
@@ -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,
},
});
@@ -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
@@ -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,
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "AssignmentReasonEnum" ADD VALUE 'RR_REASSIGNED';
+1
View File
@@ -1784,6 +1784,7 @@ enum AssignmentReasonEnum {
ROUTING_FORM_ROUTING
ROUTING_FORM_ROUTING_FALLBACK
REASSIGNED
RR_REASSIGNED
REROUTED
SALESFORCE_ASSIGNMENT
}
@@ -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;