Files
calendar/apps/api/v2/test/fixtures/repository/oauth-client.repository.fixture.ts
T
Lauris SkraucisandGitHub a44bcafcf2 feat: v2 managed organizations (#19341)
* refactor: allow non unique PlatformBilling customerId

* feat: add PlatformBilling managed organizations fields

* feat: ManagedOrganization table

* refactor: bill overdue based on teamId

* refactor: restructure organizations module

* wip: organizations endpoints

* Revert "wip: organizations endpoints"

This reverts commit 0e9e66fc74f31da436f12930c1b6597c650ed621.

* refactor: unique index for managed organizations

* wip: organizations endpoints

* wip: create managed organization

* remove unecessary membership check because we have guard

* feat: create managed org

* feat: get managed org and orgs

* feat: update and delete managed orgs

* wip: api key logic

* feat: allow variable api key length

* feat: refresh managed org api key

* feat: create managed org OAuth clients using api key

* finish merge main

* chore: bump platform libraries

* tests: fix and add more tests to api-auth.strategy.e2e

* refactor: dont request managed org slug and handle metadata as object

* revert: billing service and repository update overdue based on sub and customer ids

* refactor: v2 OAuth client permissions (#19501)

* refactor: v2 permissions as string array

* refactor: frontend work with permissions as string

* tests: test '*' permissions

* fix:managed org creator have profile & test can fetch oauth client

* fix: tests

* fix: OAuthClientCard on frontend

* fix: tests
2025-02-25 18:10:46 -07:00

58 lines
1.8 KiB
TypeScript

import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
import { TestingModule } from "@nestjs/testing";
import { PlatformOAuthClient, Prisma } from "@prisma/client";
import { CreateOAuthClientInput } from "@calcom/platform-types";
export class OAuthClientRepositoryFixture {
private prismaReadClient: PrismaReadService["prisma"];
private prismaWriteClient: PrismaWriteService["prisma"];
constructor(private readonly module: TestingModule) {
this.prismaReadClient = module.get(PrismaReadService).prisma;
this.prismaWriteClient = module.get(PrismaWriteService).prisma;
}
async get(clientId: PlatformOAuthClient["id"]) {
return this.prismaReadClient.platformOAuthClient.findFirst({ where: { id: clientId } });
}
async getByOrgId(orgId: PlatformOAuthClient["organizationId"]) {
return this.prismaReadClient.platformOAuthClient.findMany({ where: { organizationId: orgId } });
}
async getUsers(clientId: PlatformOAuthClient["id"]) {
const response = await this.prismaReadClient.platformOAuthClient.findFirst({
where: { id: clientId },
include: {
users: true,
},
});
return response?.users;
}
async create(
organizationId: number,
data: Omit<Prisma.PlatformOAuthClientCreateInput, "organization" | "secret">,
secret: string
) {
return this.prismaWriteClient.platformOAuthClient.create({
data: {
...data,
secret,
organizationId,
},
});
}
async delete(clientId: PlatformOAuthClient["id"]) {
return this.prismaWriteClient.platformOAuthClient.delete({ where: { id: clientId } });
}
async deleteByClientId(clientId: PlatformOAuthClient["id"]) {
return this.prismaWriteClient.platformOAuthClient.delete({ where: { id: clientId } });
}
}