feat: usage base billed - license key check - move to private api (#15222)
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
1 parent
53c37a9ddf
commit
e16662e655
16 files changed
+586
-59
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import LicenseKeyService, { UsageEvent } from "@calcom/ee/common/server/LicenseKeyService";
|
||||
|
||||
export function usageTrackingExtention() {
|
||||
return Prisma.defineExtension({
|
||||
query: {
|
||||
booking: {
|
||||
async create({ args, query }) {
|
||||
try {
|
||||
const licenseKeyService = await LicenseKeyService.create();
|
||||
await licenseKeyService.incrementUsage();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return query(args);
|
||||
},
|
||||
},
|
||||
user: {
|
||||
async create({ args, query }) {
|
||||
try {
|
||||
const licenseKeyService = await LicenseKeyService.create();
|
||||
await licenseKeyService.incrementUsage(UsageEvent.USER);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return query(args);
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { withAccelerate } from "@prisma/extension-accelerate";
|
||||
|
||||
import { bookingIdempotencyKeyExtension } from "./extensions/booking-idempotency-key";
|
||||
import { excludePendingPaymentsExtension } from "./extensions/exclude-pending-payment-teams";
|
||||
import { usageTrackingExtention } from "./extensions/usage-tracking";
|
||||
import { bookingReferenceMiddleware } from "./middleware";
|
||||
|
||||
const prismaOptions: Prisma.PrismaClientOptions = {};
|
||||
@@ -21,6 +22,7 @@ const prismaWithoutClientExtensions =
|
||||
|
||||
export const customPrisma = (options?: Prisma.PrismaClientOptions) =>
|
||||
new PrismaClientWithoutExtension({ ...prismaOptions, ...options })
|
||||
.$extends(usageTrackingExtention())
|
||||
.$extends(excludePendingPaymentsExtension())
|
||||
.$extends(bookingIdempotencyKeyExtension())
|
||||
.$extends(withAccelerate());
|
||||
@@ -32,6 +34,7 @@ bookingReferenceMiddleware(prismaWithoutClientExtensions);
|
||||
// FIXME: Due to some reason, there are types failing in certain places due to the $extends. Fix it and then enable it
|
||||
// Specifically we get errors like `Type 'string | Date | null | undefined' is not assignable to type 'Exact<string | Date | null | undefined, string | Date | null | undefined>'`
|
||||
const prismaWithClientExtensions = prismaWithoutClientExtensions
|
||||
.$extends(usageTrackingExtention())
|
||||
.$extends(excludePendingPaymentsExtension())
|
||||
.$extends(bookingIdempotencyKeyExtension())
|
||||
.$extends(withAccelerate());
|
||||
|
||||
Reference in new issue
Block a user