mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-24 12:34:10 +03:00
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:
parent
b1171e22a3
commit
fc820f47b2
@ -25,3 +25,4 @@ SIGN_IN_PREFILLED=true
|
||||
# LOGGER_DRIVER=console
|
||||
# SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx
|
||||
# LOG_LEVEL=error,warn
|
||||
# FLEXIBLE_BACKEND_ENABLED=false
|
@ -44,6 +44,9 @@ export class ClientConfig {
|
||||
@Field(() => Boolean)
|
||||
debugMode: boolean;
|
||||
|
||||
@Field(() => Boolean)
|
||||
flexibleBackendEnabled: boolean;
|
||||
|
||||
@Field(() => Support)
|
||||
support: Support;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ export class ClientConfigResolver {
|
||||
},
|
||||
signInPrefilled: this.environmentService.isSignInPrefilled(),
|
||||
debugMode: this.environmentService.isDebugMode(),
|
||||
flexibleBackendEnabled:
|
||||
this.environmentService.isFlexibleBackendEnabled(),
|
||||
support: {
|
||||
supportDriver: this.environmentService.getSupportDriver(),
|
||||
supportFrontChatId: this.environmentService.getSupportFrontChatId(),
|
||||
|
@ -29,6 +29,10 @@ export class EnvironmentService {
|
||||
);
|
||||
}
|
||||
|
||||
isFlexibleBackendEnabled(): boolean {
|
||||
return this.configService.get<boolean>('FLEXIBLE_BACKEND_ENABLED') ?? false;
|
||||
}
|
||||
|
||||
getPort(): number {
|
||||
return this.configService.get<number>('PORT') ?? 3000;
|
||||
}
|
||||
|
@ -46,6 +46,11 @@ export class EnvironmentVariables {
|
||||
@IsBoolean()
|
||||
TELEMETRY_ANONYMIZATION_ENABLED?: boolean;
|
||||
|
||||
@CastToBoolean()
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
FLEXIBLE_BACKEND_ENABLED?: boolean;
|
||||
|
||||
@CastToPositiveNumber()
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { Args, Query, Resolver } from '@nestjs/graphql';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { ForbiddenException, UseGuards } from '@nestjs/common';
|
||||
|
||||
import { Workspace } from '@prisma/client';
|
||||
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { EnvironmentService } from 'src/integrations/environment/environment.service';
|
||||
|
||||
import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';
|
||||
import { UniversalService } from './universal.service';
|
||||
@ -16,13 +17,20 @@ import { UpdateOneCustomArgs } from './args/update-one-custom.args';
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => UniversalEntity)
|
||||
export class UniversalResolver {
|
||||
constructor(private readonly customService: UniversalService) {}
|
||||
constructor(
|
||||
private readonly customService: UniversalService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
@Query(() => PaginatedUniversalEntity)
|
||||
findMany(
|
||||
@Args() args: FindManyUniversalArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<PaginatedUniversalEntity> {
|
||||
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return this.customService.findManyUniversal(args, workspace);
|
||||
}
|
||||
|
||||
@ -31,11 +39,19 @@ export class UniversalResolver {
|
||||
@Args() args: FindUniqueUniversalArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<UniversalEntity | undefined> {
|
||||
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return this.customService.findUniqueUniversal(args, workspace);
|
||||
}
|
||||
|
||||
@Query(() => UniversalEntity)
|
||||
updateOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return {
|
||||
id: 'exampleId',
|
||||
data: {},
|
||||
@ -46,6 +62,10 @@ export class UniversalResolver {
|
||||
|
||||
@Query(() => UniversalEntity)
|
||||
deleteOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||
if (!this.environmentService.isFlexibleBackendEnabled()) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return {
|
||||
id: 'exampleId',
|
||||
data: {},
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { DataSourceService } from 'src/tenant/metadata/data-source/data-source.service';
|
||||
import { EnvironmentService } from 'src/integrations/environment/environment.service';
|
||||
|
||||
import { UniversalService } from './universal.service';
|
||||
|
||||
@ -15,6 +16,10 @@ describe('UniversalService', () => {
|
||||
provide: DataSourceService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: EnvironmentService,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user