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:
@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user