Skip to content

Commit b0999ab

Browse files
authored
fix: Generate new idempotency key when round robin reassigning (calcom#22065)
* Create idempotencyKeyService * Use `idempotencyKeyService` in middleware * Use `idempotencyKeyService` in RR reassignments
1 parent 2bbd92d commit b0999ab

4 files changed

Lines changed: 42 additions & 7 deletions

File tree

packages/features/ee/round-robin/roundRobinManualReassignment.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { SENDER_NAME } from "@calcom/lib/constants";
2424
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
2525
import { getEventName } from "@calcom/lib/event";
2626
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
27+
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
2728
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
2829
import logger from "@calcom/lib/logger";
2930
import { getTranslation } from "@calcom/lib/server/i18n";
@@ -181,6 +182,12 @@ export const roundRobinManualReassignment = async ({
181182
userPrimaryEmail: newUser.email,
182183
reassignReason,
183184
reassignById: reassignedById,
185+
idempotencyKey: IdempotencyKeyService.generate({
186+
startTime: booking.startTime,
187+
endTime: booking.endTime,
188+
userId: newUser.id,
189+
reassignedById,
190+
}),
184191
},
185192
select: bookingSelect,
186193
});

packages/features/ee/round-robin/roundRobinReassignment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
enrichUserWithDelegationCredentialsIncludeServiceAccountKey,
2222
} from "@calcom/lib/delegationCredential/server";
2323
import { getEventName } from "@calcom/lib/event";
24+
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
25+
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
2426
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
2527
import logger from "@calcom/lib/logger";
2628
import { getLuckyUser } from "@calcom/lib/server/getLuckyUser";
@@ -238,6 +240,12 @@ export const roundRobinReassignment = async ({
238240
userId: reassignedRRHost.id,
239241
userPrimaryEmail: reassignedRRHost.email,
240242
title: newBookingTitle,
243+
idempotencyKey: IdempotencyKeyService.generate({
244+
startTime: booking.startTime,
245+
endTime: booking.endTime,
246+
userId: reassignedRRHost.id,
247+
reassignedById,
248+
}),
241249
},
242250
select: bookingSelect,
243251
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { v5 as uuidv5 } from "uuid";
2+
3+
export class IdempotencyKeyService {
4+
static generate({
5+
startTime,
6+
endTime,
7+
userId,
8+
reassignedById,
9+
}: {
10+
startTime: Date | string;
11+
endTime: Date | string;
12+
userId?: number;
13+
reassignedById?: number | null;
14+
}) {
15+
return uuidv5(
16+
`${startTime.valueOf()}.${endTime.valueOf()}.${userId}${reassignedById ? `.${reassignedById}` : ""}`,
17+
uuidv5.URL
18+
);
19+
}
20+
}

packages/prisma/extensions/booking-idempotency-key.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Prisma } from "@prisma/client";
2-
import { v5 as uuidv5 } from "uuid";
32

3+
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
44
import { BookingStatus } from "@calcom/prisma/enums";
55

66
export function bookingIdempotencyKeyExtension() {
@@ -9,12 +9,12 @@ export function bookingIdempotencyKeyExtension() {
99
booking: {
1010
async create({ args, query }) {
1111
if (args.data.status === BookingStatus.ACCEPTED) {
12-
const idempotencyKey = uuidv5(
13-
`${args.data.startTime.valueOf()}.${args.data.endTime.valueOf()}.${
14-
args.data?.user?.connect?.id
15-
}${args.data?.reassignById ? `.${args.data.reassignById}` : ""}`,
16-
uuidv5.URL
17-
);
12+
const idempotencyKey = IdempotencyKeyService.generate({
13+
startTime: args.data.startTime,
14+
endTime: args.data.endTime,
15+
userId: args.data.user?.connect?.id,
16+
reassignedById: args.data.reassignById,
17+
});
1818
args.data.idempotencyKey = idempotencyKey;
1919
}
2020
return query(args);

0 commit comments

Comments
 (0)