The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
chore: drop findMany and findUnique resolvers for custom objects (#1897)
gitstart-twenty2ff35083fba1
diff --git a/server/src/tenant/universal/args/find-many-universal.args.ts b/server/src/tenant/universal/args/find-many-universal.args.tsdeleted file mode 100644index 082d42cafc2..00000000000--- a/server/src/tenant/universal/args/find-many-universal.args.ts+++ /dev/null@@ -1,35 +0,0 @@-import { ArgsType, Field, Int } from '@nestjs/graphql';--import GraphQLJSON from 'graphql-type-json';-import { IsNotEmpty, IsString } from 'class-validator';--import { ConnectionArgs } from 'src/utils/pagination';--import { UniversalEntityInput } from './universal-entity.input';-import { UniversalEntityOrderByRelationInput } from './universal-entity-order-by-relation.input';--@ArgsType()-export class FindManyUniversalArgs extends ConnectionArgs {- @Field(() => String)- @IsNotEmpty()- @IsString()- entity: string;-- @Field(() => UniversalEntityInput, { nullable: true })- where?: UniversalEntityInput;-- @Field(() => UniversalEntityOrderByRelationInput, { nullable: true })- orderBy?: UniversalEntityOrderByRelationInput;-- @Field(() => GraphQLJSON, { nullable: true })- cursor?: UniversalEntityInput;-- @Field(() => Int, { nullable: true })- take?: number;-- @Field(() => Int, { nullable: true })- skip?: number;-- @Field(() => [String], { nullable: true })- distinct?: Array<string>;-}diff --git a/server/src/tenant/universal/args/find-unique-universal.args.ts b/server/src/tenant/universal/args/find-unique-universal.args.tsdeleted file mode 100644index 85432323b3a..00000000000--- a/server/src/tenant/universal/args/find-unique-universal.args.ts+++ /dev/null@@ -1,10 +0,0 @@-import { ArgsType, Field } from '@nestjs/graphql';--import { BaseUniversalArgs } from './base-universal.args';-import { UniversalEntityInput } from './universal-entity.input';--@ArgsType()-export class FindUniqueUniversalArgs extends BaseUniversalArgs {- @Field(() => UniversalEntityInput, { nullable: true })- where?: UniversalEntityInput;-}diff --git a/server/src/tenant/universal/universal.module.ts b/server/src/tenant/universal/universal.module.tsindex edf22bed2ec..fe2715522d9 100644--- a/server/src/tenant/universal/universal.module.ts+++ b/server/src/tenant/universal/universal.module.ts@@ -2,11 +2,10 @@ import { Module } from '@nestjs/common';import { DataSourceModule } from 'src/metadata/data-source/data-source.module';-import { UniversalService } from './universal.service';import { UniversalResolver } from './universal.resolver';@Module({imports: [DataSourceModule],- providers: [UniversalService, UniversalResolver],+ providers: [UniversalResolver],})export class UniversalModule {}diff --git a/server/src/tenant/universal/universal.resolver.spec.ts b/server/src/tenant/universal/universal.resolver.spec.tsindex a5b6515fa04..5a253380019 100644--- a/server/src/tenant/universal/universal.resolver.spec.ts+++ b/server/src/tenant/universal/universal.resolver.spec.ts@@ -3,7 +3,6 @@ import { Test, TestingModule } from '@nestjs/testing';import { EnvironmentService } from 'src/integrations/environment/environment.service';import { UniversalResolver } from './universal.resolver';-import { UniversalService } from './universal.service';describe('UniversalResolver', () => {let resolver: UniversalResolver;@@ -12,10 +11,6 @@ describe('UniversalResolver', () => {const module: TestingModule = await Test.createTestingModule({providers: [UniversalResolver,- {- provide: UniversalService,- useValue: {},- },{provide: EnvironmentService,useValue: {},diff --git a/server/src/tenant/universal/universal.resolver.ts b/server/src/tenant/universal/universal.resolver.tsindex 0cd484fe365..cf0ffeee63b 100644--- a/server/src/tenant/universal/universal.resolver.ts+++ b/server/src/tenant/universal/universal.resolver.ts@@ -1,49 +1,15 @@-import { Args, Query, Resolver } from '@nestjs/graphql';+import { Query, Resolver } from '@nestjs/graphql';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';--import { FindManyUniversalArgs } from './args/find-many-universal.args';-import { FindUniqueUniversalArgs } from './args/find-unique-universal.args';+import { UniversalEntity } from './universal.entity';@UseGuards(JwtAuthGuard)@Resolver(() => UniversalEntity)export class UniversalResolver {- 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);- }-- @Query(() => UniversalEntity)- findUnique(- @Args() args: FindUniqueUniversalArgs,- @AuthWorkspace() workspace: Workspace,- ): Promise<UniversalEntity | undefined> {- if (!this.environmentService.isFlexibleBackendEnabled()) {- throw new ForbiddenException();- }-- return this.customService.findUniqueUniversal(args, workspace);- }+ constructor(private readonly environmentService: EnvironmentService) {}@Query(() => UniversalEntity)updateOneCustom(): UniversalEntity {diff --git a/server/src/tenant/universal/universal.service.spec.ts b/server/src/tenant/universal/universal.service.spec.tsdeleted file mode 100644index c432917d841..00000000000--- a/server/src/tenant/universal/universal.service.spec.ts+++ /dev/null@@ -1,32 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing';--import { DataSourceService } from 'src/metadata/data-source/data-source.service';-import { EnvironmentService } from 'src/integrations/environment/environment.service';--import { UniversalService } from './universal.service';--describe('UniversalService', () => {- let service: UniversalService;-- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- providers: [- UniversalService,- {- provide: DataSourceService,- useValue: {},- },- {- provide: EnvironmentService,- useValue: {},- },- ],- }).compile();-- service = module.get<UniversalService>(UniversalService);- });-- it('should be defined', () => {- expect(service).toBeDefined();- });-});diff --git a/server/src/tenant/universal/universal.service.ts b/server/src/tenant/universal/universal.service.tsdeleted file mode 100644index d5aadc0fd90..00000000000--- a/server/src/tenant/universal/universal.service.ts+++ /dev/null@@ -1,100 +0,0 @@-import { Injectable, InternalServerErrorException } from '@nestjs/common';--import { Workspace } from '@prisma/client';--import { DataSourceService } from 'src/metadata/data-source/data-source.service';-import { findManyCursorConnection } from 'src/utils/pagination';--import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';-import {- getRawTypeORMOrderByClause,- getRawTypeORMWhereClause,-} from './universal.util';--import { FindManyUniversalArgs } from './args/find-many-universal.args';-import { FindUniqueUniversalArgs } from './args/find-unique-universal.args';--@Injectable()-export class UniversalService {- constructor(private readonly dataSourceService: DataSourceService) {}-- async findManyUniversal(- args: FindManyUniversalArgs,- workspace: Workspace,- ): Promise<PaginatedUniversalEntity> {- await this.dataSourceService.createWorkspaceSchema(workspace.id);-- const workspaceDataSource =- await this.dataSourceService.connectToWorkspaceDataSource(workspace.id);-- let query = workspaceDataSource- ?.createQueryBuilder()- .select()- .from(args.entity, args.entity);-- if (!query) {- throw new InternalServerErrorException();- }-- if (query && args.where) {- const { where, parameters } = getRawTypeORMWhereClause(- args.entity,- args.where,- );-- query = query.where(where, parameters);- }-- if (query && args.orderBy) {- const orderBy = getRawTypeORMOrderByClause(args.entity, args.orderBy);-- query = query.orderBy(orderBy);- }-- return findManyCursorConnection(query, args, {- recordToEdge({ id, createdAt, updatedAt, ...data }) {- return {- node: {- id,- data,- createdAt,- updatedAt,- },- };- },- });- }-- async findUniqueUniversal(- args: FindUniqueUniversalArgs,- workspace: Workspace,- ): Promise<UniversalEntity | undefined> {- await this.dataSourceService.createWorkspaceSchema(workspace.id);-- const workspaceDataSource =- await this.dataSourceService.connectToWorkspaceDataSource(workspace.id);-- let query = workspaceDataSource- ?.createQueryBuilder()- .select()- .from(args.entity, args.entity);-- if (query && args.where) {- const { where, parameters } = getRawTypeORMWhereClause(- args.entity,- args.where,- );-- query = query.where(where, parameters);- }-- const { id, createdAt, updatedAt, ...data } = await query?.getRawOne();-- return {- id,- data,- createdAt,- updatedAt,- };- }-}