Feat/disable flexible backend (#1673)
* wip: refacto and start creating custom resolver * feat: findMany & findUnique of a custom entity * feat: wip pagination * feat: initial metadata migration * feat: universal findAll with pagination * fix: clean small stuff in pagination * fix: test * fix: miss file * feat: rename custom into universal * feat: enable/disable flexible backend from env --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -24,4 +24,5 @@ SIGN_IN_PREFILLED=true
|
|||||||
# SUPPORT_FRONT_CHAT_ID=replace_me_with_front_chat_id
|
# SUPPORT_FRONT_CHAT_ID=replace_me_with_front_chat_id
|
||||||
# LOGGER_DRIVER=console
|
# LOGGER_DRIVER=console
|
||||||
# SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx
|
# SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx
|
||||||
# LOG_LEVEL=error,warn
|
# LOG_LEVEL=error,warn
|
||||||
|
# FLEXIBLE_BACKEND_ENABLED=false
|
||||||
@ -44,6 +44,9 @@ export class ClientConfig {
|
|||||||
@Field(() => Boolean)
|
@Field(() => Boolean)
|
||||||
debugMode: boolean;
|
debugMode: boolean;
|
||||||
|
|
||||||
|
@Field(() => Boolean)
|
||||||
|
flexibleBackendEnabled: boolean;
|
||||||
|
|
||||||
@Field(() => Support)
|
@Field(() => Support)
|
||||||
support: Support;
|
support: Support;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,8 @@ export class ClientConfigResolver {
|
|||||||
},
|
},
|
||||||
signInPrefilled: this.environmentService.isSignInPrefilled(),
|
signInPrefilled: this.environmentService.isSignInPrefilled(),
|
||||||
debugMode: this.environmentService.isDebugMode(),
|
debugMode: this.environmentService.isDebugMode(),
|
||||||
|
flexibleBackendEnabled:
|
||||||
|
this.environmentService.isFlexibleBackendEnabled(),
|
||||||
support: {
|
support: {
|
||||||
supportDriver: this.environmentService.getSupportDriver(),
|
supportDriver: this.environmentService.getSupportDriver(),
|
||||||
supportFrontChatId: this.environmentService.getSupportFrontChatId(),
|
supportFrontChatId: this.environmentService.getSupportFrontChatId(),
|
||||||
|
|||||||
@ -29,6 +29,10 @@ export class EnvironmentService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isFlexibleBackendEnabled(): boolean {
|
||||||
|
return this.configService.get<boolean>('FLEXIBLE_BACKEND_ENABLED') ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
getPort(): number {
|
getPort(): number {
|
||||||
return this.configService.get<number>('PORT') ?? 3000;
|
return this.configService.get<number>('PORT') ?? 3000;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,11 @@ export class EnvironmentVariables {
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
TELEMETRY_ANONYMIZATION_ENABLED?: boolean;
|
TELEMETRY_ANONYMIZATION_ENABLED?: boolean;
|
||||||
|
|
||||||
|
@CastToBoolean()
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
FLEXIBLE_BACKEND_ENABLED?: boolean;
|
||||||
|
|
||||||
@CastToPositiveNumber()
|
@CastToPositiveNumber()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { Args, Query, Resolver } from '@nestjs/graphql';
|
import { Args, Query, Resolver } from '@nestjs/graphql';
|
||||||
import { UseGuards } from '@nestjs/common';
|
import { ForbiddenException, UseGuards } from '@nestjs/common';
|
||||||
|
|
||||||
import { Workspace } from '@prisma/client';
|
import { Workspace } from '@prisma/client';
|
||||||
|
|
||||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||||
|
import { EnvironmentService } from 'src/integrations/environment/environment.service';
|
||||||
|
|
||||||
import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';
|
import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';
|
||||||
import { UniversalService } from './universal.service';
|
import { UniversalService } from './universal.service';
|
||||||
@ -16,13 +17,20 @@ import { UpdateOneCustomArgs } from './args/update-one-custom.args';
|
|||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Resolver(() => UniversalEntity)
|
@Resolver(() => UniversalEntity)
|
||||||
export class UniversalResolver {
|
export class UniversalResolver {
|
||||||
constructor(private readonly customService: UniversalService) {}
|
constructor(
|
||||||
|
private readonly customService: UniversalService,
|
||||||
|
private readonly environmentService: EnvironmentService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@Query(() => PaginatedUniversalEntity)
|
@Query(() => PaginatedUniversalEntity)
|
||||||
findMany(
|
findMany(
|
||||||
@Args() args: FindManyUniversalArgs,
|
@Args() args: FindManyUniversalArgs,
|
||||||
@AuthWorkspace() workspace: Workspace,
|
@AuthWorkspace() workspace: Workspace,
|
||||||
): Promise<PaginatedUniversalEntity> {
|
): Promise<PaginatedUniversalEntity> {
|
||||||
|
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
return this.customService.findManyUniversal(args, workspace);
|
return this.customService.findManyUniversal(args, workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,11 +39,19 @@ export class UniversalResolver {
|
|||||||
@Args() args: FindUniqueUniversalArgs,
|
@Args() args: FindUniqueUniversalArgs,
|
||||||
@AuthWorkspace() workspace: Workspace,
|
@AuthWorkspace() workspace: Workspace,
|
||||||
): Promise<UniversalEntity | undefined> {
|
): Promise<UniversalEntity | undefined> {
|
||||||
|
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
return this.customService.findUniqueUniversal(args, workspace);
|
return this.customService.findUniqueUniversal(args, workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => UniversalEntity)
|
@Query(() => UniversalEntity)
|
||||||
updateOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
updateOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||||
|
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'exampleId',
|
id: 'exampleId',
|
||||||
data: {},
|
data: {},
|
||||||
@ -46,6 +62,10 @@ export class UniversalResolver {
|
|||||||
|
|
||||||
@Query(() => UniversalEntity)
|
@Query(() => UniversalEntity)
|
||||||
deleteOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
deleteOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||||
|
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'exampleId',
|
id: 'exampleId',
|
||||||
data: {},
|
data: {},
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
|
||||||
import { DataSourceService } from 'src/tenant/metadata/data-source/data-source.service';
|
import { DataSourceService } from 'src/tenant/metadata/data-source/data-source.service';
|
||||||
|
import { EnvironmentService } from 'src/integrations/environment/environment.service';
|
||||||
|
|
||||||
import { UniversalService } from './universal.service';
|
import { UniversalService } from './universal.service';
|
||||||
|
|
||||||
@ -15,6 +16,10 @@ describe('UniversalService', () => {
|
|||||||
provide: DataSourceService,
|
provide: DataSourceService,
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: EnvironmentService,
|
||||||
|
useValue: {},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user