remove nestjs-query from user and workspace resolvers (#22766)
## What Migrates the `user` and `workspace` core modules off `@ptc-org/nestjs-query`. Both used `NestjsQueryGraphQLModule` only as scaffolding — all CRUD was disabled and the real GraphQL API is already served by the hand-written `UserResolver` / `WorkspaceResolver`. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/22766?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@@ -3,7 +3,6 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import assert from 'assert';
|
||||
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { SOURCE_LOCALE } from 'twenty-shared/translations';
|
||||
import { assertIsDefinedOrThrow, isDefined } from 'twenty-shared/utils';
|
||||
@@ -52,7 +51,7 @@ import { STANDARD_ROLE } from 'src/engine/workspace-manager/twenty-standard-appl
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
|
||||
// oxlint-disable-next-line twenty/inject-workspace-repository
|
||||
export class UserService extends TypeOrmQueryService<UserEntity> {
|
||||
export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(UserEntity)
|
||||
private readonly userRepository: Repository<UserEntity>,
|
||||
@@ -70,9 +69,7 @@ export class UserService extends TypeOrmQueryService<UserEntity> {
|
||||
private readonly coreEntityCacheService: CoreEntityCacheService,
|
||||
private readonly workspaceMemberTranspiler: WorkspaceMemberTranspiler,
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
) {
|
||||
super(userRepository);
|
||||
}
|
||||
) {}
|
||||
|
||||
async refreshWorkspaceIfPendingOrOngoingCreation<
|
||||
TWorkspace extends Pick<WorkspaceEntity, 'id' | 'activationStatus'>,
|
||||
@@ -86,7 +83,9 @@ export class UserService extends TypeOrmQueryService<UserEntity> {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
const freshWorkspace = await this.workspaceService.findById(workspace.id);
|
||||
const freshWorkspace = await this.workspaceService.findOneWorkspaceById(
|
||||
workspace.id,
|
||||
);
|
||||
|
||||
return freshWorkspace ?? workspace;
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import {
|
||||
type AutoResolverOpts,
|
||||
PagingStrategies,
|
||||
type ReadResolverOpts,
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
|
||||
import { UserEntity } from 'src/engine/core-modules/user/user.entity';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
|
||||
export const userAutoResolverOpts: AutoResolverOpts<
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
any,
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
any,
|
||||
unknown,
|
||||
unknown,
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
ReadResolverOpts<any>,
|
||||
PagingStrategies
|
||||
>[] = [
|
||||
{
|
||||
EntityClass: UserEntity,
|
||||
DTOClass: UserEntity,
|
||||
enableTotalCount: true,
|
||||
pagingStrategy: PagingStrategies.CURSOR,
|
||||
read: {
|
||||
many: { disabled: true },
|
||||
one: { disabled: true },
|
||||
},
|
||||
create: {
|
||||
many: { disabled: true },
|
||||
one: { disabled: true },
|
||||
},
|
||||
update: {
|
||||
many: { disabled: true },
|
||||
one: { disabled: true },
|
||||
},
|
||||
delete: { many: { disabled: true }, one: { disabled: true } },
|
||||
guards: [WorkspaceAuthGuard],
|
||||
},
|
||||
];
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
import { APP_LOCALES, SOURCE_LOCALE } from 'twenty-shared/translations';
|
||||
import {
|
||||
BeforeInsert,
|
||||
@@ -36,7 +35,7 @@ registerEnumType(OnboardingStatus, {
|
||||
where: '"deletedAt" IS NULL',
|
||||
})
|
||||
export class UserEntity {
|
||||
@IDField(() => UUIDScalarType)
|
||||
@Field(() => UUIDScalarType)
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { NestjsQueryGraphQLModule } from '@ptc-org/nestjs-query-graphql';
|
||||
import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm';
|
||||
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { CoreEntityCacheModule } from 'src/engine/core-entity-cache/core-entity-cache.module';
|
||||
import { WorkspaceDomainsModule } from 'src/engine/core-modules/domain/workspace-domains/workspace-domains.module';
|
||||
@@ -23,26 +20,17 @@ import { UserEntity } from 'src/engine/core-modules/user/user.entity';
|
||||
import { UserResolver } from 'src/engine/core-modules/user/user.resolver';
|
||||
import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module';
|
||||
import { ConnectedAccountMetadataModule } from 'src/engine/metadata-modules/connected-account/connected-account-metadata.module';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
|
||||
import { UserRoleModule } from 'src/engine/metadata-modules/user-role/user-role.module';
|
||||
import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
|
||||
|
||||
import { userAutoResolverOpts } from './user.auto-resolver-opts';
|
||||
|
||||
import { UserService } from './services/user.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
NestjsQueryGraphQLModule.forFeature({
|
||||
imports: [
|
||||
NestjsQueryTypeOrmModule.forFeature([UserEntity]),
|
||||
TypeORMModule,
|
||||
FileModule,
|
||||
],
|
||||
resolvers: userAutoResolverOpts,
|
||||
}),
|
||||
NestjsQueryTypeOrmModule.forFeature([ObjectMetadataEntity]),
|
||||
TypeOrmModule.forFeature([UserEntity]),
|
||||
TypeORMModule,
|
||||
FileModule,
|
||||
WorkspaceModule,
|
||||
OnboardingModule,
|
||||
TypeOrmModule.forFeature([KeyValuePairEntity, UserWorkspaceEntity]),
|
||||
|
||||
+2
-5
@@ -4,7 +4,6 @@ import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
||||
import assert from 'assert';
|
||||
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
|
||||
import { PermissionFlagType } from 'twenty-shared/constants';
|
||||
import { assertIsDefinedOrThrow, isDefined } from 'twenty-shared/utils';
|
||||
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
|
||||
@@ -83,7 +82,7 @@ const WORKSPACE_ACTIVATION_STALE_LOCK_TIMEOUT_MS = 5 * 60 * 1000;
|
||||
|
||||
@Injectable()
|
||||
// oxlint-disable-next-line twenty/inject-workspace-repository
|
||||
export class WorkspaceService extends TypeOrmQueryService<WorkspaceEntity> {
|
||||
export class WorkspaceService {
|
||||
protected readonly logger = new Logger(WorkspaceService.name);
|
||||
|
||||
private readonly WORKSPACE_FIELD_PERMISSIONS: Record<
|
||||
@@ -149,9 +148,7 @@ export class WorkspaceService extends TypeOrmQueryService<WorkspaceEntity> {
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
private readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,
|
||||
private readonly sdkClientGenerationService: SdkClientGenerationService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
) {}
|
||||
|
||||
async updateWorkspaceById({
|
||||
payload,
|
||||
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
import {
|
||||
type AutoResolverOpts,
|
||||
PagingStrategies,
|
||||
type ReadResolverOpts,
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
|
||||
import { UpdateWorkspaceInput } from 'src/engine/core-modules/workspace/dtos/update-workspace-input';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
export const workspaceAutoResolverOpts: AutoResolverOpts<
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
any,
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
any,
|
||||
unknown,
|
||||
unknown,
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
ReadResolverOpts<any>,
|
||||
PagingStrategies
|
||||
>[] = [
|
||||
{
|
||||
EntityClass: WorkspaceEntity,
|
||||
DTOClass: WorkspaceEntity,
|
||||
UpdateDTOClass: UpdateWorkspaceInput,
|
||||
enableTotalCount: true,
|
||||
pagingStrategy: PagingStrategies.CURSOR,
|
||||
read: {
|
||||
many: { disabled: true },
|
||||
one: { disabled: true },
|
||||
},
|
||||
create: {
|
||||
many: { disabled: true },
|
||||
one: { disabled: true },
|
||||
},
|
||||
update: {
|
||||
one: { disabled: true },
|
||||
many: { disabled: true },
|
||||
},
|
||||
delete: { many: { disabled: true }, one: { disabled: true } },
|
||||
guards: [WorkspaceAuthGuard],
|
||||
},
|
||||
];
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
import { type Application } from 'cloudflare/resources/zero-trust/access/applications/applications';
|
||||
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
|
||||
import {
|
||||
@@ -70,7 +69,7 @@ registerEnumType(WorkspaceDiscoverability, {
|
||||
@ObjectType('Workspace')
|
||||
export class WorkspaceEntity {
|
||||
// Fields
|
||||
@IDField(() => UUIDScalarType)
|
||||
@Field(() => UUIDScalarType)
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { NestjsQueryGraphQLModule } from '@ptc-org/nestjs-query-graphql';
|
||||
import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm';
|
||||
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
|
||||
import { PreInstalledAppsModule } from 'src/engine/core-modules/application/pre-installed-apps/pre-installed-apps.module';
|
||||
@@ -19,7 +16,6 @@ import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-
|
||||
import { FileModule } from 'src/engine/core-modules/file/file.module';
|
||||
import { MetricsModule } from 'src/engine/core-modules/metrics/metrics.module';
|
||||
import { OnboardingModule } from 'src/engine/core-modules/onboarding/onboarding.module';
|
||||
import { PublicDomainEntity } from 'src/engine/core-modules/public-domain/public-domain.entity';
|
||||
import { SdkClientModule } from 'src/engine/core-modules/sdk-client/sdk-client.module';
|
||||
import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { UserWorkspaceModule } from 'src/engine/core-modules/user-workspace/user-workspace.module';
|
||||
@@ -31,7 +27,6 @@ import { CoreEntityCacheModule } from 'src/engine/core-entity-cache/core-entity-
|
||||
import { WorkspaceEntityCacheProviderService } from 'src/engine/core-modules/workspace/services/workspace-entity-cache-provider.service';
|
||||
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
|
||||
import { WorkspaceGaugeService } from 'src/engine/core-modules/workspace/workspace-gauge.service';
|
||||
import { workspaceAutoResolverOpts } from 'src/engine/core-modules/workspace/workspace.auto-resolver-opts';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceResolver } from 'src/engine/core-modules/workspace/workspace.resolver';
|
||||
import { BillingDisabledGuard } from 'src/engine/guards/billing-disabled.guard';
|
||||
@@ -50,49 +45,40 @@ import { StandardObjectsPrefillModule } from 'src/engine/workspace-manager/stand
|
||||
@Module({
|
||||
imports: [
|
||||
TypeORMModule,
|
||||
TypeOrmModule.forFeature([BillingSubscriptionEntity, WorkspaceEntity]),
|
||||
TypeOrmModule.forFeature([
|
||||
BillingSubscriptionEntity,
|
||||
WorkspaceEntity,
|
||||
UserEntity,
|
||||
UserWorkspaceEntity,
|
||||
]),
|
||||
MetricsModule,
|
||||
StandardObjectsPrefillModule,
|
||||
NestjsQueryGraphQLModule.forFeature({
|
||||
imports: [
|
||||
BillingModule,
|
||||
FileModule,
|
||||
TokenModule,
|
||||
NestjsQueryTypeOrmModule.forFeature([
|
||||
UserEntity,
|
||||
WorkspaceEntity,
|
||||
UserWorkspaceEntity,
|
||||
PublicDomainEntity,
|
||||
]),
|
||||
ObjectMetadataModule,
|
||||
UserWorkspaceModule,
|
||||
WorkspaceManagerModule,
|
||||
FeatureFlagModule,
|
||||
OnboardingModule,
|
||||
WorkspaceDataSourceModule,
|
||||
TypeORMModule,
|
||||
PermissionsModule,
|
||||
WorkspaceCacheStorageModule,
|
||||
RoleModule,
|
||||
AiAgentModule,
|
||||
DnsManagerModule,
|
||||
WorkspaceDomainsModule,
|
||||
SubdomainManagerModule,
|
||||
CustomDomainManagerModule,
|
||||
ViewModule,
|
||||
WorkspaceManyOrAllFlatEntityMapsCacheModule,
|
||||
ApplicationModule,
|
||||
PreInstalledAppsModule,
|
||||
EnterpriseModule,
|
||||
StandardObjectsPrefillModule,
|
||||
WorkspaceMigrationModule,
|
||||
CoreEntityCacheModule,
|
||||
UpgradeModule,
|
||||
SdkClientModule,
|
||||
],
|
||||
services: [WorkspaceService],
|
||||
resolvers: workspaceAutoResolverOpts,
|
||||
}),
|
||||
BillingModule,
|
||||
FileModule,
|
||||
TokenModule,
|
||||
ObjectMetadataModule,
|
||||
UserWorkspaceModule,
|
||||
WorkspaceManagerModule,
|
||||
FeatureFlagModule,
|
||||
OnboardingModule,
|
||||
WorkspaceDataSourceModule,
|
||||
PermissionsModule,
|
||||
WorkspaceCacheStorageModule,
|
||||
RoleModule,
|
||||
AiAgentModule,
|
||||
DnsManagerModule,
|
||||
WorkspaceDomainsModule,
|
||||
SubdomainManagerModule,
|
||||
CustomDomainManagerModule,
|
||||
ViewModule,
|
||||
WorkspaceManyOrAllFlatEntityMapsCacheModule,
|
||||
ApplicationModule,
|
||||
PreInstalledAppsModule,
|
||||
EnterpriseModule,
|
||||
WorkspaceMigrationModule,
|
||||
CoreEntityCacheModule,
|
||||
UpgradeModule,
|
||||
SdkClientModule,
|
||||
],
|
||||
exports: [WorkspaceService, CheckCustomDomainValidRecordsCronCommand],
|
||||
providers: [
|
||||
|
||||
@@ -105,7 +105,7 @@ export class WorkspaceResolver {
|
||||
@Query(() => WorkspaceEntity)
|
||||
@UseGuards(WorkspaceAuthGuard, NoPermissionGuard)
|
||||
async currentWorkspace(@AuthWorkspace() { id }: WorkspaceEntity) {
|
||||
const workspace = await this.workspaceService.findById(id);
|
||||
const workspace = await this.workspaceService.findOneWorkspaceById(id);
|
||||
|
||||
assert(workspace, 'Workspace not found');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user