Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ for Logger level to be set at info, for example.
</details>

If you don't want to create a local DB. Then you can also consider using services like railway.app, Northflank or render.


- [Setup postgres DB with railway.app](https://docs.railway.app/guides/postgresql)
- [Setup postgres DB with Northflank](https://northflank.com/guides/deploy-postgres-database-on-northflank)
Expand All @@ -235,6 +236,15 @@ for Logger level to be set at info, for example.
yarn workspace @calcom/prisma db-deploy
```

**Note for Windows/PowerShell users:** If running the database deployment scripts fails with an error stating `Environment variable not found: DATABASE_DIRECT_URL`, Turbo might be failing to inject the root `.env` variables. You can bypass this by executing the commands directly from the prisma package directory in PowerShell:

```powershell
cd packages/prisma
$env:DATABASE_URL="postgresql://postgres:YOUR_PASSWORD@localhost:5432/postgres"; $env:DATABASE_DIRECT_URL="postgresql://postgres:YOUR_PASSWORD@localhost:5432/postgres"
npx prisma db push
cd ../..
```

4. Run [mailhog](https://github.com/mailhog/MailHog) to view emails sent during development

> **_NOTE:_** Required when `E2E_TEST_MAILHOG_ENABLED` is "1"
Expand Down
40 changes: 40 additions & 0 deletions packages/app-store/repositories/PrismaCredentialRepository.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
27 changes: 6 additions & 21 deletions packages/app-store/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import type { TFunction } from "i18next";

import { enrichUserWithDelegationConferencingCredentialsWithoutOrgId } from "@calcom/app-store/delegationCredential";
import { defaultVideoAppCategories } from "@calcom/app-store/utils";
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential";
import { prisma } from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import { AppCategories } from "@calcom/prisma/enums";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import { PrismaCredentialRepository } from "./repositories/PrismaCredentialRepository";

import getEnabledAppsFromCredentials from "./_utils/getEnabledAppsFromCredentials";
import { defaultLocations } from "./locations";
Expand Down Expand Up @@ -62,23 +61,10 @@ export async function getLocationGroupedOptions(
});
}

const nonDelegationCredentials = await prisma.credential.findMany({
where: {
...idToSearchObject,
app: {
categories: {
hasSome: defaultVideoAppCategories,
},
},
},
select: {
...credentialForCalendarServiceSelect,
team: {
select: {
name: true,
},
},
},
const credentialRepository = new PrismaCredentialRepository(prisma);
const nonDelegationCredentials = await credentialRepository.findNonDelegationCredentialsByAppCategories({
idToSearchObject,
appCategories: defaultVideoAppCategories,
});

let credentials;
Expand All @@ -94,8 +80,7 @@ export async function getLocationGroupedOptions(
);
credentials = allCredentials;
} else {
// TODO: We can avoid calling buildNonDelegationCredentials here by moving the above prisma query to the repository and doing it there
credentials = buildNonDelegationCredentials(nonDelegationCredentials);
credentials = nonDelegationCredentials;
}

const integrations = await getEnabledAppsFromCredentials(credentials, { filterOnCredentials: true });
Expand Down
Loading