* fix timezone display on booking page to reflect event availability timezone * migrate fetching event owner's schedule to server side * migrate fetching event owner's schedule to server side * fix e2e test errors * Add WEBAPP_URL_FOR_OAUTH to salesforce auth * In event manager constructor include "_crm" credentials as calendar creds * Change crm apps to type to end with `_crm` * Move sendgrid out of CRM * Add zoho bigin to CRM apps * When getting apps, use slug * Add `crm` variants * Hubspot Oauth use `WEBAPP_URL_FOR_OAUTH` * Refactor creating credentials * Fix empty CRM page * Use credentials with `_crm` * Abstract getAppCategoryTitle * Add integration.handler changes * When searching for credential, look for current credentials in class * On cancel, delete 3rd party events * Fix tests * Type fix * Type fixes * Remove apiDeletes * Type fixes * Specific typing --------- Co-authored-by: Shaik-Sirajuddin <sirajuddinshaik30gmail.com> Co-authored-by: Shaik-Sirajuddin <sirajudddinshaik30@gmail.com> Co-authored-by: Shaik-Sirajuddin <89742297+Shaik-Sirajuddin@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Omar López <zomars@me.com>
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import type { Prisma } from "@prisma/client";
|
|
|
|
import { UserRepository } from "@calcom/lib/server/repository/user";
|
|
import type { userSelect } from "@calcom/prisma";
|
|
import prisma from "@calcom/prisma";
|
|
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
|
|
|
type User = Prisma.UserGetPayload<typeof userSelect>;
|
|
|
|
/**
|
|
* Gets credentials from the user, team, and org if applicable
|
|
*
|
|
*/
|
|
export const getAllCredentials = async (
|
|
user: { id: number; username: string | null; credentials: CredentialPayload[] },
|
|
eventType: { team: { id: number | null } | null; parentId: number | null } | null
|
|
) => {
|
|
const allCredentials = user.credentials;
|
|
|
|
// If it's a team event type query for team credentials
|
|
if (eventType?.team?.id) {
|
|
const teamCredentialsQuery = await prisma.credential.findMany({
|
|
where: {
|
|
teamId: eventType.team.id,
|
|
},
|
|
select: credentialForCalendarServiceSelect,
|
|
});
|
|
allCredentials.push(...teamCredentialsQuery);
|
|
}
|
|
|
|
// If it's a managed event type, query for the parent team's credentials
|
|
if (eventType?.parentId) {
|
|
const teamCredentialsQuery = await prisma.team.findFirst({
|
|
where: {
|
|
eventTypes: {
|
|
some: {
|
|
id: eventType.parentId,
|
|
},
|
|
},
|
|
},
|
|
select: {
|
|
credentials: {
|
|
select: credentialForCalendarServiceSelect,
|
|
},
|
|
},
|
|
});
|
|
if (teamCredentialsQuery?.credentials) {
|
|
allCredentials.push(...teamCredentialsQuery?.credentials);
|
|
}
|
|
}
|
|
|
|
const { profile } = await UserRepository.enrichUserWithItsProfile({
|
|
user: user,
|
|
});
|
|
|
|
// If the user is a part of an organization, query for the organization's credentials
|
|
if (profile?.organizationId) {
|
|
const org = await prisma.team.findUnique({
|
|
where: {
|
|
id: profile.organizationId,
|
|
},
|
|
select: {
|
|
credentials: {
|
|
select: credentialForCalendarServiceSelect,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (org?.credentials) {
|
|
allCredentials.push(...org.credentials);
|
|
}
|
|
}
|
|
|
|
return allCredentials;
|
|
};
|