fix: Generate new idempotency key when round robin reassigning (#22065)

* Create idempotencyKeyService

* Use `idempotencyKeyService` in middleware

* Use `idempotencyKeyService` in RR reassignments
This commit is contained in:
Joe Au-Yeung
2025-06-26 17:43:31 +00:00
committed by GitHub
parent 2bbd92db13
commit b0999abc68
4 changed files with 42 additions and 7 deletions
@@ -24,6 +24,7 @@ import { SENDER_NAME } from "@calcom/lib/constants";
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
import { getEventName } from "@calcom/lib/event";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
import logger from "@calcom/lib/logger";
import { getTranslation } from "@calcom/lib/server/i18n";
@@ -181,6 +182,12 @@ export const roundRobinManualReassignment = async ({
userPrimaryEmail: newUser.email,
reassignReason,
reassignById: reassignedById,
idempotencyKey: IdempotencyKeyService.generate({
startTime: booking.startTime,
endTime: booking.endTime,
userId: newUser.id,
reassignedById,
}),
},
select: bookingSelect,
});
@@ -21,6 +21,8 @@ import {
enrichUserWithDelegationCredentialsIncludeServiceAccountKey,
} from "@calcom/lib/delegationCredential/server";
import { getEventName } from "@calcom/lib/event";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
import logger from "@calcom/lib/logger";
import { getLuckyUser } from "@calcom/lib/server/getLuckyUser";
@@ -238,6 +240,12 @@ export const roundRobinReassignment = async ({
userId: reassignedRRHost.id,
userPrimaryEmail: reassignedRRHost.email,
title: newBookingTitle,
idempotencyKey: IdempotencyKeyService.generate({
startTime: booking.startTime,
endTime: booking.endTime,
userId: reassignedRRHost.id,
reassignedById,
}),
},
select: bookingSelect,
});
@@ -0,0 +1,20 @@
import { v5 as uuidv5 } from "uuid";
export class IdempotencyKeyService {
static generate({
startTime,
endTime,
userId,
reassignedById,
}: {
startTime: Date | string;
endTime: Date | string;
userId?: number;
reassignedById?: number | null;
}) {
return uuidv5(
`${startTime.valueOf()}.${endTime.valueOf()}.${userId}${reassignedById ? `.${reassignedById}` : ""}`,
uuidv5.URL
);
}
}
@@ -1,6 +1,6 @@
import { Prisma } from "@prisma/client";
import { v5 as uuidv5 } from "uuid";
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
import { BookingStatus } from "@calcom/prisma/enums";
export function bookingIdempotencyKeyExtension() {
@@ -9,12 +9,12 @@ export function bookingIdempotencyKeyExtension() {
booking: {
async create({ args, query }) {
if (args.data.status === BookingStatus.ACCEPTED) {
const idempotencyKey = uuidv5(
`${args.data.startTime.valueOf()}.${args.data.endTime.valueOf()}.${
args.data?.user?.connect?.id
}${args.data?.reassignById ? `.${args.data.reassignById}` : ""}`,
uuidv5.URL
);
const idempotencyKey = IdempotencyKeyService.generate({
startTime: args.data.startTime,
endTime: args.data.endTime,
userId: args.data.user?.connect?.id,
reassignedById: args.data.reassignById,
});
args.data.idempotencyKey = idempotencyKey;
}
return query(args);