refactor(app-store): move credential query to repository pattern (#29724)
* refactor(app-store): move credential query to repository pattern * chore: removed unused imports
This commit is contained in:
1 parent
f3284f581f
commit
ca90ca2c94
2 files changed
+46
-21
No files matched your search
@@ -0,0 +1,40 @@
|
|||||||
|
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential";
|
||||||
|
import { prisma } from "@calcom/prisma";
|
||||||
|
import type { Prisma } from "@calcom/prisma/client";
|
||||||
|
import type { AppCategories } from "@calcom/prisma/client";
|
||||||
|
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||||
|
|
||||||
|
export class PrismaCredentialRepository {
|
||||||
|
constructor(private readonly prismaClient: typeof prisma){}
|
||||||
|
|
||||||
|
async findNonDelegationCredentialsByAppCategories({
|
||||||
|
idToSearchObject,
|
||||||
|
appCategories,
|
||||||
|
}: {
|
||||||
|
idToSearchObject: Prisma.CredentialWhereInput;
|
||||||
|
appCategories: AppCategories[];
|
||||||
|
}){
|
||||||
|
|
||||||
|
const credentials = await this.prismaClient.credential.findMany({
|
||||||
|
where: {
|
||||||
|
...idToSearchObject,
|
||||||
|
app: {
|
||||||
|
categories: {
|
||||||
|
hasSome: appCategories
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
...credentialForCalendarServiceSelect,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
return buildNonDelegationCredentials(credentials)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,10 @@ import type { TFunction } from "i18next";
|
|||||||
|
|
||||||
import { enrichUserWithDelegationConferencingCredentialsWithoutOrgId } from "@calcom/app-store/delegationCredential";
|
import { enrichUserWithDelegationConferencingCredentialsWithoutOrgId } from "@calcom/app-store/delegationCredential";
|
||||||
import { defaultVideoAppCategories } from "@calcom/app-store/utils";
|
import { defaultVideoAppCategories } from "@calcom/app-store/utils";
|
||||||
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential";
|
|
||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import type { Prisma } from "@calcom/prisma/client";
|
import type { Prisma } from "@calcom/prisma/client";
|
||||||
import { AppCategories } from "@calcom/prisma/enums";
|
import { AppCategories } from "@calcom/prisma/enums";
|
||||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
import { PrismaCredentialRepository } from "./repositories/PrismaCredentialRepository";
|
||||||
|
|
||||||
import getEnabledAppsFromCredentials from "./_utils/getEnabledAppsFromCredentials";
|
import getEnabledAppsFromCredentials from "./_utils/getEnabledAppsFromCredentials";
|
||||||
import { defaultLocations } from "./locations";
|
import { defaultLocations } from "./locations";
|
||||||
@@ -62,23 +61,10 @@ export async function getLocationGroupedOptions(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const nonDelegationCredentials = await prisma.credential.findMany({
|
const credentialRepository = new PrismaCredentialRepository(prisma);
|
||||||
where: {
|
const nonDelegationCredentials = await credentialRepository.findNonDelegationCredentialsByAppCategories({
|
||||||
...idToSearchObject,
|
idToSearchObject,
|
||||||
app: {
|
appCategories: defaultVideoAppCategories,
|
||||||
categories: {
|
|
||||||
hasSome: defaultVideoAppCategories,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
...credentialForCalendarServiceSelect,
|
|
||||||
team: {
|
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let credentials;
|
let credentials;
|
||||||
@@ -94,8 +80,7 @@ export async function getLocationGroupedOptions(
|
|||||||
);
|
);
|
||||||
credentials = allCredentials;
|
credentials = allCredentials;
|
||||||
} else {
|
} else {
|
||||||
// TODO: We can avoid calling buildNonDelegationCredentials here by moving the above prisma query to the repository and doing it there
|
credentials = nonDelegationCredentials;
|
||||||
credentials = buildNonDelegationCredentials(nonDelegationCredentials);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const integrations = await getEnabledAppsFromCredentials(credentials, { filterOnCredentials: true });
|
const integrations = await getEnabledAppsFromCredentials(credentials, { filterOnCredentials: true });
|
||||||
|
|||||||
Reference in new issue
Block a user