<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Switch @calcom/prisma to use relative imports for client and enums. This removes self-references, stabilizes builds, and improves type resolution. - **Refactors** - Replaced imports from "@calcom/prisma/*" with local "./client" and "./enums" across extensions, selects, mocks, and availability check. - Updated safeJSONStringify parameter type from any to unknown. - Minor formatting cleanup in zod-utils. <sup>Written for commit 85c0a7b75fb1291be5b848a73d1ccb5543283f49. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { v5 as uuidv5 } from "uuid";
|
|
|
|
import { Prisma } from "../client";
|
|
import { BookingStatus } from "../enums";
|
|
|
|
function generateIdempotencyKey({
|
|
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
|
|
);
|
|
}
|
|
|
|
export function bookingIdempotencyKeyExtension() {
|
|
return Prisma.defineExtension({
|
|
query: {
|
|
booking: {
|
|
async create({ args, query }) {
|
|
if (args.data.status === BookingStatus.ACCEPTED) {
|
|
const idempotencyKey = generateIdempotencyKey({
|
|
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);
|
|
},
|
|
async update({ args, query }) {
|
|
if (args.data.status === BookingStatus.CANCELLED || args.data.status === BookingStatus.REJECTED) {
|
|
args.data.idempotencyKey = null;
|
|
}
|
|
return query(args);
|
|
},
|
|
async updateMany({ args, query }) {
|
|
if (args.data.status === BookingStatus.CANCELLED || args.data.status === BookingStatus.REJECTED) {
|
|
args.data.idempotencyKey = null;
|
|
}
|
|
return query(args);
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|