chore: booking verification token and booking rejection logic from email (#16324)

Co-authored-by: Omar López <[email protected]>
This commit is contained in:
Anik Dhabal BabuandOmar López authored and GitHub committed 2024-09-21 02:25:27 +00:00
1 parent 76a2773688
commit 1a60afad7a
19 files changed
+362 -8

No files matched your search

+1
View File
@@ -14,4 +14,5 @@ export type AppFlags = {
"google-workspace-directory": boolean;
"disable-signup": boolean;
attributes: boolean;
"organizer-request-email-v2": boolean;
};
@@ -0,0 +1,5 @@
export interface IFeaturesRepository {
checkIfUserHasFeature(userId: number, slug: string): Promise<boolean>;
checkIfTeamHasFeature(teamId: number, slug: string): Promise<boolean>;
checkIfTeamOrUserHasFeature(args: { teamId?: number; userId?: number }, slug: string): Promise<boolean>;
}
@@ -0,0 +1,59 @@
import { captureException } from "@sentry/nextjs";
import db from "@calcom/prisma";
import type { IFeaturesRepository } from "./features.repository.interface";
export class FeaturesRepository implements IFeaturesRepository {
async checkIfTeamHasFeature(teamId: number, slug: string) {
try {
const teamFeature = await db.teamFeatures.findUnique({
where: {
teamId_featureId: { teamId, featureId: slug },
},
});
return !!teamFeature;
} catch (err) {
captureException(err);
throw err;
}
}
async checkIfUserHasFeature(userId: number, slug: string) {
try {
const userFeature = await db.userFeatures.findUnique({
where: {
userId_featureId: { userId, featureId: slug },
},
});
return !!userFeature;
} catch (err) {
captureException(err);
throw err;
}
}
async checkIfTeamOrUserHasFeature(
args: {
teamId?: number;
userId?: number;
},
slug: string
) {
const { teamId, userId } = args;
try {
if (teamId) {
const teamHasFeature = await this.checkIfTeamHasFeature(teamId, slug);
if (teamHasFeature) return true;
}
if (userId) {
const userHasFeature = await this.checkIfUserHasFeature(userId, slug);
if (userHasFeature) return true;
}
return false;
} catch (err) {
captureException(err);
throw err;
}
}
}