diff --git a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-core-batch.controller.ts b/packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core-batch.controller.ts similarity index 86% rename from packages/twenty-server/src/engine/api/rest/controllers/rest-api-core-batch.controller.ts rename to packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core-batch.controller.ts index 6f35ed834d..e77ae4c891 100644 --- a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-core-batch.controller.ts +++ b/packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core-batch.controller.ts @@ -2,7 +2,7 @@ import { Controller, Post, Req, Res } from '@nestjs/common'; import { Request, Response } from 'express'; -import { RestApiCoreService } from 'src/engine/api/rest/services/rest-api-core.service'; +import { RestApiCoreService } from 'src/engine/api/rest/core/rest-api-core.service'; import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils'; @Controller('rest/batch/*') diff --git a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-core.controller.ts b/packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core.controller.ts similarity index 94% rename from packages/twenty-server/src/engine/api/rest/controllers/rest-api-core.controller.ts rename to packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core.controller.ts index fe2dfacaea..5fd46c49a2 100644 --- a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-core.controller.ts +++ b/packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core.controller.ts @@ -11,7 +11,7 @@ import { import { Request, Response } from 'express'; -import { RestApiCoreService } from 'src/engine/api/rest/services/rest-api-core.service'; +import { RestApiCoreService } from 'src/engine/api/rest/core/rest-api-core.service'; import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils'; @Controller('rest/*') diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.factory.ts similarity index 76% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.factory.ts index d7f0d6d185..bd2bda31d9 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.factory.ts @@ -2,24 +2,24 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { Request } from 'express'; -import { DeleteQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-query.factory'; +import { DeleteQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/delete-query.factory'; import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service'; import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; -import { CreateOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory'; -import { UpdateQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory'; -import { FindOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory'; -import { FindManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory'; -import { DeleteVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory'; -import { CreateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory'; -import { UpdateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory'; -import { GetVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory'; -import { parseCorePath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-path.utils'; -import { computeDepth } from 'src/engine/api/rest/rest-api-core-query-builder/utils/compute-depth.utils'; +import { CreateOneQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/create-one-query.factory'; +import { UpdateQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/update-query.factory'; +import { FindOneQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/find-one-query.factory'; +import { FindManyQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/find-many-query.factory'; +import { DeleteVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/delete-variables.factory'; +import { CreateVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/create-variables.factory'; +import { UpdateVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/update-variables.factory'; +import { GetVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/get-variables.factory'; +import { parseCorePath } from 'src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-path.utils'; +import { computeDepth } from 'src/engine/api/rest/core/query-builder/utils/compute-depth.utils'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { Query } from 'src/engine/api/rest/types/query.type'; +import { Query } from 'src/engine/api/rest/core/types/query.type'; import { EnvironmentService } from 'src/engine/integrations/environment/environment.service'; -import { CreateManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory'; -import { parseCoreBatchPath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-batch-path.utils'; +import { CreateManyQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/create-many-query.factory'; +import { parseCoreBatchPath } from 'src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-batch-path.utils'; @Injectable() export class CoreQueryBuilderFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.module.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.module.ts similarity index 64% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.module.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.module.ts index 8e91f11742..38b5ec398c 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/core-query-builder.module.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/core-query-builder.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; -import { CoreQueryBuilderFactory } from 'src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory'; -import { coreQueryBuilderFactories } from 'src/engine/api/rest/rest-api-core-query-builder/factories/factories'; +import { CoreQueryBuilderFactory } from 'src/engine/api/rest/core/query-builder/core-query-builder.factory'; +import { coreQueryBuilderFactories } from 'src/engine/api/rest/core/query-builder/factories/factories'; import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module'; import { AuthModule } from 'src/engine/core-modules/auth/auth.module'; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-many-query.factory.ts similarity index 92% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-many-query.factory.ts index 02c8714f44..b02bf194bb 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-many-query.factory.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { capitalize } from 'src/utils/capitalize'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; @Injectable() export class CreateManyQueryFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-one-query.factory.ts similarity index 91% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-one-query.factory.ts index a7135605eb..e807889893 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-one-query.factory.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { capitalize } from 'src/utils/capitalize'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; @Injectable() export class CreateOneQueryFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-variables.factory.ts similarity index 83% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-variables.factory.ts index eb4b20ef1c..02bc3f9d6a 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/create-variables.factory.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { Request } from 'express'; -import { QueryVariables } from 'src/engine/api/rest/types/query-variables.type'; +import { QueryVariables } from 'src/engine/api/rest/core/types/query-variables.type'; @Injectable() export class CreateVariablesFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/delete-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/delete-query.factory.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/delete-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/delete-query.factory.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/delete-variables.factory.ts similarity index 67% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/delete-variables.factory.ts index c41c2073c2..a1a5a40bd2 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/delete-variables.factory.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; -import { QueryVariables } from 'src/engine/api/rest/types/query-variables.type'; +import { QueryVariables } from 'src/engine/api/rest/core/types/query-variables.type'; @Injectable() export class DeleteVariablesFactory { diff --git a/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/factories.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/factories.ts new file mode 100644 index 0000000000..00faf41ca5 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/factories.ts @@ -0,0 +1,25 @@ +import { DeleteQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/delete-query.factory'; +import { CreateOneQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/create-one-query.factory'; +import { UpdateQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/update-query.factory'; +import { FindOneQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/find-one-query.factory'; +import { FindManyQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/find-many-query.factory'; +import { DeleteVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/delete-variables.factory'; +import { CreateVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/create-variables.factory'; +import { UpdateVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/update-variables.factory'; +import { GetVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/get-variables.factory'; +import { CreateManyQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/create-many-query.factory'; +import { inputFactories } from 'src/engine/api/rest/input-factories/factories'; + +export const coreQueryBuilderFactories = [ + DeleteQueryFactory, + CreateOneQueryFactory, + CreateManyQueryFactory, + UpdateQueryFactory, + FindOneQueryFactory, + FindManyQueryFactory, + DeleteVariablesFactory, + CreateVariablesFactory, + UpdateVariablesFactory, + GetVariablesFactory, + ...inputFactories, +]; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-many-query.factory.ts similarity index 82% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-many-query.factory.ts index 4f3cb7c72d..401721162d 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-many-query.factory.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { capitalize } from 'src/utils/capitalize'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; @Injectable() export class FindManyQueryFactory { @@ -17,10 +17,16 @@ export class FindManyQueryFactory { $orderBy: [${objectNameSingular}OrderByInput], $startingAfter: String, $endingBefore: String, - $limit: Int = 60 + $first: Int, + $last: Int ) { ${objectNamePlural}( - filter: $filter, orderBy: $orderBy, first: $limit, after: $startingAfter, before: $endingBefore + filter: $filter, + orderBy: $orderBy, + first: $first, + last: $last, + after: $startingAfter, + before: $endingBefore ) { edges { node { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-one-query.factory.ts similarity index 91% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-one-query.factory.ts index 9286080be1..cc2b498710 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/find-one-query.factory.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { capitalize } from 'src/utils/capitalize'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; @Injectable() export class FindOneQueryFactory { diff --git a/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/get-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/get-variables.factory.ts new file mode 100644 index 0000000000..5af552d48f --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/get-variables.factory.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@nestjs/common'; + +import { Request } from 'express'; + +import { LimitInputFactory } from 'src/engine/api/rest/input-factories/limit-input.factory'; +import { OrderByInputFactory } from 'src/engine/api/rest/input-factories/order-by-input.factory'; +import { FilterInputFactory } from 'src/engine/api/rest/input-factories/filter-input.factory'; +import { QueryVariables } from 'src/engine/api/rest/core/types/query-variables.type'; +import { EndingBeforeInputFactory } from 'src/engine/api/rest/input-factories/ending-before-input.factory'; +import { StartingAfterInputFactory } from 'src/engine/api/rest/input-factories/starting-after-input.factory'; + +@Injectable() +export class GetVariablesFactory { + constructor( + private readonly startingAfterInputFactory: StartingAfterInputFactory, + private readonly endingBeforeInputFactory: EndingBeforeInputFactory, + private readonly limitInputFactory: LimitInputFactory, + private readonly orderByInputFactory: OrderByInputFactory, + private readonly filterInputFactory: FilterInputFactory, + ) {} + + create( + id: string | undefined, + request: Request, + objectMetadata, + ): QueryVariables { + if (id) { + return { filter: { id: { eq: id } } }; + } + + const limit = this.limitInputFactory.create(request); + const endingBefore = this.endingBeforeInputFactory.create(request); + const startingAfter = this.startingAfterInputFactory.create(request); + + return { + filter: this.filterInputFactory.create(request, objectMetadata), + orderBy: this.orderByInputFactory.create(request, objectMetadata), + first: !endingBefore ? limit : undefined, + last: endingBefore ? limit : undefined, + startingAfter, + endingBefore, + }; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-query.factory.ts similarity index 91% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-query.factory.ts index ca7e9cd03d..f578b2d18e 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-query.factory.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { capitalize } from 'src/utils/capitalize'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; @Injectable() export class UpdateQueryFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-variables.factory.ts similarity index 74% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-variables.factory.ts index 588288bf92..c911faa03a 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/factories/update-variables.factory.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { Request } from 'express'; -import { QueryVariables } from 'src/engine/api/rest/types/query-variables.type'; +import { QueryVariables } from 'src/engine/api/rest/core/types/query-variables.type'; @Injectable() export class UpdateVariablesFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/check-fields.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/check-fields.utils.spec.ts similarity index 81% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/check-fields.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/check-fields.utils.spec.ts index 4dbbfdde09..865eac4bc2 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/check-fields.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/check-fields.utils.spec.ts @@ -1,6 +1,6 @@ import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock'; -import { checkFields } from 'src/engine/api/rest/rest-api-core-query-builder/utils/check-fields.utils'; -import { checkArrayFields } from 'src/engine/api/rest/rest-api-core-query-builder/utils/check-order-by.utils'; +import { checkFields } from 'src/engine/api/rest/core/query-builder/utils/check-fields.utils'; +import { checkArrayFields } from 'src/engine/api/rest/core/query-builder/utils/check-order-by.utils'; describe('checkFields', () => { it('should check field types', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/compute-depth.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/compute-depth.utils.spec.ts similarity index 84% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/compute-depth.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/compute-depth.utils.spec.ts index a6909574a6..cf68056a3b 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/compute-depth.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/compute-depth.utils.spec.ts @@ -1,4 +1,4 @@ -import { computeDepth } from 'src/engine/api/rest/rest-api-core-query-builder/utils/compute-depth.utils'; +import { computeDepth } from 'src/engine/api/rest/core/query-builder/utils/compute-depth.utils'; describe('computeDepth', () => { it('should compute depth from query', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/get-field-type.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/get-field-type.utils.spec.ts similarity index 78% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/get-field-type.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/get-field-type.utils.spec.ts index 6c09709c20..ec6854bc48 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/get-field-type.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/get-field-type.utils.spec.ts @@ -1,6 +1,6 @@ import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock'; import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; -import { getFieldType } from 'src/engine/api/rest/rest-api-core-query-builder/utils/get-field-type.utils'; +import { getFieldType } from 'src/engine/api/rest/core/query-builder/utils/get-field-type.utils'; describe('getFieldType', () => { it('should get field type', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts similarity index 91% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts index 76dbe1b732..b06c26ec36 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts @@ -5,7 +5,7 @@ import { fieldTextMock, objectMetadataItemMock, } from 'src/engine/api/__mocks__/object-metadata-item.mock'; -import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; describe('mapFieldMetadataToGraphqlQuery', () => { it('should map properly', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/check-fields.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/check-fields.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/check-fields.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/check-fields.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/check-order-by.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/check-order-by.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/check-order-by.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/check-order-by.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/compute-depth.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/compute-depth.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/compute-depth.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/compute-depth.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/add-default-conjunction.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/add-default-conjunction.utils.spec.ts similarity index 81% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/add-default-conjunction.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/add-default-conjunction.utils.spec.ts index 8adda48359..1b949c8551 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/add-default-conjunction.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/add-default-conjunction.utils.spec.ts @@ -1,4 +1,4 @@ -import { addDefaultConjunctionIfMissing } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils'; +import { addDefaultConjunctionIfMissing } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils'; describe('addDefaultConjunctionIfMissing', () => { it('should add default conjunction if missing', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-enum-values.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-enum-values.spec.ts similarity index 84% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-enum-values.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-enum-values.spec.ts index 4e4694c110..8c24bce858 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-enum-values.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-enum-values.spec.ts @@ -1,4 +1,4 @@ -import { checkFilterEnumValues } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-enum-values'; +import { checkFilterEnumValues } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-enum-values'; import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; import { fieldSelectMock, diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-query.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-query.utils.spec.ts similarity index 86% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-query.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-query.utils.spec.ts index fc1f3e8187..7cba92df6d 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/check-filter-query.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/check-filter-query.utils.spec.ts @@ -1,4 +1,4 @@ -import { checkFilterQuery } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-query.utils'; +import { checkFilterQuery } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-query.utils'; describe('checkFilterQuery', () => { it('should check filter query', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/format-field-values.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/format-field-values.utils.spec.ts similarity index 92% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/format-field-values.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/format-field-values.utils.spec.ts index eb94f88b31..6787ccc3ee 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/format-field-values.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/format-field-values.utils.spec.ts @@ -1,5 +1,5 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; -import { formatFieldValue } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/format-field-values.utils'; +import { formatFieldValue } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/format-field-values.utils'; describe('formatFieldValue', () => { it('should format fieldNumber value', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-base-filter.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-base-filter.utils.spec.ts similarity index 90% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-base-filter.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-base-filter.utils.spec.ts index c522b00bde..dc41296b7a 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-base-filter.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-base-filter.utils.spec.ts @@ -1,4 +1,4 @@ -import { parseBaseFilter } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils'; +import { parseBaseFilter } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils'; describe('parseBaseFilter', () => { it('should parse simple filter string test 1', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter-content.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter-content.utils.spec.ts similarity index 91% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter-content.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter-content.utils.spec.ts index ed0efea1c2..884c672395 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter-content.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter-content.utils.spec.ts @@ -1,4 +1,4 @@ -import { parseFilterContent } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter-content.utils'; +import { parseFilterContent } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter-content.utils'; describe('parseFilterContent', () => { it('should parse query filter test 1', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter.utils.spec.ts similarity index 94% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter.utils.spec.ts index 3dfdd2b75b..b92b09c96b 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/__tests__/parse-filter.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/__tests__/parse-filter.utils.spec.ts @@ -1,5 +1,5 @@ import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock'; -import { parseFilter } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils'; +import { parseFilter } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils'; describe('parseFilter', () => { it('should parse string filter test 1', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils.ts similarity index 67% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils.ts index 03f66456e8..f30bf375d2 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils.ts @@ -1,4 +1,4 @@ -import { Conjunctions } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils'; +import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils'; export const DEFAULT_CONJUNCTION = Conjunctions.and; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-enum-values.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-enum-values.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-enum-values.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-enum-values.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-query.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-query.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-query.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-query.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/format-field-values.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/format-field-values.utils.ts similarity index 93% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/format-field-values.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/format-field-values.utils.ts index eeab31d674..79e351f941 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/format-field-values.utils.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/format-field-values.utils.ts @@ -1,7 +1,7 @@ import { BadRequestException } from '@nestjs/common'; import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; -import { FieldValue } from 'src/engine/api/rest/types/field-value.type'; +import { FieldValue } from 'src/engine/api/rest/core/types/field-value.type'; export const formatFieldValue = ( value: string, diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter-content.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter-content.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter-content.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter-content.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils.ts similarity index 65% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils.ts index ac8307d873..0f8a043b3b 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils.ts @@ -2,13 +2,13 @@ import { BadRequestException } from '@nestjs/common'; import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface'; -import { parseFilterContent } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter-content.utils'; -import { parseBaseFilter } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils'; -import { checkFields } from 'src/engine/api/rest/rest-api-core-query-builder/utils/check-fields.utils'; -import { formatFieldValue } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/format-field-values.utils'; -import { FieldValue } from 'src/engine/api/rest/types/field-value.type'; -import { checkFilterEnumValues } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-enum-values'; -import { getFieldType } from 'src/engine/api/rest/rest-api-core-query-builder/utils/get-field-type.utils'; +import { parseFilterContent } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter-content.utils'; +import { parseBaseFilter } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils'; +import { checkFields } from 'src/engine/api/rest/core/query-builder/utils/check-fields.utils'; +import { formatFieldValue } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/format-field-values.utils'; +import { FieldValue } from 'src/engine/api/rest/core/types/field-value.type'; +import { checkFilterEnumValues } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-enum-values'; +import { getFieldType } from 'src/engine/api/rest/core/query-builder/utils/get-field-type.utils'; export enum Conjunctions { or = 'or', diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/get-field-type.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/get-field-type.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/get-field-type.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/get-field-type.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/map-field-metadata-to-graphql-query.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts similarity index 65% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts index 0413152110..a66400eecb 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-batch-path.utils.spec.ts @@ -1,4 +1,4 @@ -import { parseCoreBatchPath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-batch-path.utils'; +import { parseCoreBatchPath } from 'src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-batch-path.utils'; describe('parseCoreBatchPath', () => { it('should parse object from request path', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts similarity index 86% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts index 0d20d453af..c5c9434160 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/__tests__/parse-core-path.utils.spec.ts @@ -1,4 +1,4 @@ -import { parseCorePath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-path.utils'; +import { parseCorePath } from 'src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-path.utils'; describe('parseCorePath', () => { it('should parse object from request path', () => { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-batch-path.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-batch-path.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-batch-path.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-batch-path.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-path.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-path.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-core-path.utils.ts rename to packages/twenty-server/src/engine/api/rest/core/query-builder/utils/path-parsers/parse-core-path.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/services/rest-api-core.service.ts b/packages/twenty-server/src/engine/api/rest/core/rest-api-core.service.ts similarity index 88% rename from packages/twenty-server/src/engine/api/rest/services/rest-api-core.service.ts rename to packages/twenty-server/src/engine/api/rest/core/rest-api-core.service.ts index 126c64e6a3..3b56c76e51 100644 --- a/packages/twenty-server/src/engine/api/rest/services/rest-api-core.service.ts +++ b/packages/twenty-server/src/engine/api/rest/core/rest-api-core.service.ts @@ -2,11 +2,11 @@ import { Injectable } from '@nestjs/common'; import { Request } from 'express'; -import { CoreQueryBuilderFactory } from 'src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory'; +import { CoreQueryBuilderFactory } from 'src/engine/api/rest/core/query-builder/core-query-builder.factory'; import { GraphqlApiType, RestApiService, -} from 'src/engine/api/rest/services/rest-api.service'; +} from 'src/engine/api/rest/rest-api.service'; @Injectable() export class RestApiCoreService { diff --git a/packages/twenty-server/src/engine/api/rest/types/field-value.type.ts b/packages/twenty-server/src/engine/api/rest/core/types/field-value.type.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/types/field-value.type.ts rename to packages/twenty-server/src/engine/api/rest/core/types/field-value.type.ts diff --git a/packages/twenty-server/src/engine/api/rest/types/query-variables.type.ts b/packages/twenty-server/src/engine/api/rest/core/types/query-variables.type.ts similarity index 83% rename from packages/twenty-server/src/engine/api/rest/types/query-variables.type.ts rename to packages/twenty-server/src/engine/api/rest/core/types/query-variables.type.ts index 6907aed8d5..97a23c657a 100644 --- a/packages/twenty-server/src/engine/api/rest/types/query-variables.type.ts +++ b/packages/twenty-server/src/engine/api/rest/core/types/query-variables.type.ts @@ -3,7 +3,8 @@ export type QueryVariables = { data?: object | null; filter?: object; orderBy?: object; - limit?: number; + last?: number; + first?: number; startingAfter?: string; endingBefore?: string; input?: object; diff --git a/packages/twenty-server/src/engine/api/rest/core/types/query.type.ts b/packages/twenty-server/src/engine/api/rest/core/types/query.type.ts new file mode 100644 index 0000000000..92a9cf27ce --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/core/types/query.type.ts @@ -0,0 +1,6 @@ +import { QueryVariables } from 'src/engine/api/rest/core/types/query-variables.type'; + +export type Query = { + query: string; + variables: QueryVariables; +}; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/ending-before-input.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/ending-before-input.factory.spec.ts similarity index 85% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/ending-before-input.factory.spec.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/__tests__/ending-before-input.factory.spec.ts index 2de86ff7f3..9bef0dbfdc 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/ending-before-input.factory.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/ending-before-input.factory.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { EndingBeforeInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/ending-before-input.factory'; +import { EndingBeforeInputFactory } from 'src/engine/api/rest/input-factories/ending-before-input.factory'; describe('EndingBeforeInputFactory', () => { let service: EndingBeforeInputFactory; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/filter-input.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/filter-input.factory.spec.ts similarity index 96% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/filter-input.factory.spec.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/__tests__/filter-input.factory.spec.ts index 12dd667500..b6366ff703 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/filter-input.factory.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/filter-input.factory.spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock'; -import { FilterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory'; +import { FilterInputFactory } from 'src/engine/api/rest/input-factories/filter-input.factory'; describe('FilterInputFactory', () => { const objectMetadata = { objectMetadataItem: objectMetadataItemMock }; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/limit-input.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/limit-input.factory.spec.ts similarity index 90% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/limit-input.factory.spec.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/__tests__/limit-input.factory.spec.ts index 16ed18507a..2104250f1c 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/limit-input.factory.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/limit-input.factory.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { LimitInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory'; +import { LimitInputFactory } from 'src/engine/api/rest/input-factories/limit-input.factory'; describe('LimitInputFactory', () => { let service: LimitInputFactory; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/order-by-input.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/order-by-input.factory.spec.ts similarity index 96% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/order-by-input.factory.spec.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/__tests__/order-by-input.factory.spec.ts index d7ee7c1e8e..63b3179ee6 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/order-by-input.factory.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/order-by-input.factory.spec.ts @@ -3,7 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface'; import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock'; -import { OrderByInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory'; +import { OrderByInputFactory } from 'src/engine/api/rest/input-factories/order-by-input.factory'; describe('OrderByInputFactory', () => { const objectMetadata = { objectMetadataItem: objectMetadataItemMock }; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/starting-before-input.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/starting-before-input.factory.spec.ts similarity index 85% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/starting-before-input.factory.spec.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/__tests__/starting-before-input.factory.spec.ts index 484cd8da63..8147395842 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/__tests__/starting-before-input.factory.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/__tests__/starting-before-input.factory.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { StartingAfterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/starting-after-input.factory'; +import { StartingAfterInputFactory } from 'src/engine/api/rest/input-factories/starting-after-input.factory'; describe('StartingAfterInputFactory', () => { let service: StartingAfterInputFactory; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/ending-before-input.factory.ts b/packages/twenty-server/src/engine/api/rest/input-factories/ending-before-input.factory.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/ending-before-input.factory.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/ending-before-input.factory.ts diff --git a/packages/twenty-server/src/engine/api/rest/input-factories/factories.ts b/packages/twenty-server/src/engine/api/rest/input-factories/factories.ts new file mode 100644 index 0000000000..bbe17eeca1 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/input-factories/factories.ts @@ -0,0 +1,13 @@ +import { StartingAfterInputFactory } from 'src/engine/api/rest/input-factories/starting-after-input.factory'; +import { EndingBeforeInputFactory } from 'src/engine/api/rest/input-factories/ending-before-input.factory'; +import { LimitInputFactory } from 'src/engine/api/rest/input-factories/limit-input.factory'; +import { OrderByInputFactory } from 'src/engine/api/rest/input-factories/order-by-input.factory'; +import { FilterInputFactory } from 'src/engine/api/rest/input-factories/filter-input.factory'; + +export const inputFactories = [ + StartingAfterInputFactory, + EndingBeforeInputFactory, + LimitInputFactory, + OrderByInputFactory, + FilterInputFactory, +]; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory.ts b/packages/twenty-server/src/engine/api/rest/input-factories/filter-input.factory.ts similarity index 54% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/filter-input.factory.ts index 1041212dfb..93ed93d51e 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/filter-input.factory.ts @@ -2,10 +2,10 @@ import { Injectable } from '@nestjs/common'; import { Request } from 'express'; -import { addDefaultConjunctionIfMissing } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils'; -import { checkFilterQuery } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/check-filter-query.utils'; -import { parseFilter } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils'; -import { FieldValue } from 'src/engine/api/rest/types/field-value.type'; +import { addDefaultConjunctionIfMissing } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils'; +import { checkFilterQuery } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/check-filter-query.utils'; +import { parseFilter } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils'; +import { FieldValue } from 'src/engine/api/rest/core/types/field-value.type'; @Injectable() export class FilterInputFactory { diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory.ts b/packages/twenty-server/src/engine/api/rest/input-factories/limit-input.factory.ts similarity index 83% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/limit-input.factory.ts index 26d958d3a3..d7ccaddc09 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/limit-input.factory.ts @@ -4,9 +4,9 @@ import { Request } from 'express'; @Injectable() export class LimitInputFactory { - create(request: Request): number { + create(request: Request, defaultLimit = 60): number { if (!request.query.limit) { - return 60; + return defaultLimit; } const limit = +request.query.limit; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory.ts b/packages/twenty-server/src/engine/api/rest/input-factories/order-by-input.factory.ts similarity index 95% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/order-by-input.factory.ts index de073693cc..832de44c52 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory.ts +++ b/packages/twenty-server/src/engine/api/rest/input-factories/order-by-input.factory.ts @@ -7,7 +7,7 @@ import { RecordOrderBy, } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface'; -import { checkArrayFields } from 'src/engine/api/rest/rest-api-core-query-builder/utils/check-order-by.utils'; +import { checkArrayFields } from 'src/engine/api/rest/core/query-builder/utils/check-order-by.utils'; export const DEFAULT_ORDER_DIRECTION = OrderByDirection.AscNullsFirst; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/starting-after-input.factory.ts b/packages/twenty-server/src/engine/api/rest/input-factories/starting-after-input.factory.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/starting-after-input.factory.ts rename to packages/twenty-server/src/engine/api/rest/input-factories/starting-after-input.factory.ts diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/create-metadata-query.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/create-metadata-query.factory.ts new file mode 100644 index 0000000000..67333a146c --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/create-metadata-query.factory.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; + +import { capitalize } from 'src/utils/capitalize'; +import { fetchMetadataFields } from 'src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils'; + +@Injectable() +export class CreateMetadataQueryFactory { + create(objectNameSingular: string, objectNamePlural: string): string { + const objectNameCapitalized = capitalize(objectNameSingular); + + const fields = fetchMetadataFields(objectNamePlural); + + return ` + mutation Create${objectNameCapitalized}($input: CreateOne${objectNameCapitalized}${ + objectNameSingular === 'field' ? 'Metadata' : '' + }Input!) { + createOne${objectNameCapitalized}(input: $input) { + id + ${fields} + } + } + `; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/delete-metadata-query.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/delete-metadata-query.factory.ts new file mode 100644 index 0000000000..c1e09b05bd --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/delete-metadata-query.factory.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@nestjs/common'; + +import { capitalize } from 'src/utils/capitalize'; + +@Injectable() +export class DeleteMetadataQueryFactory { + create(objectNameSingular: string): string { + const objectNameCapitalized = capitalize(objectNameSingular); + + return ` + mutation Delete${objectNameCapitalized}($input: DeleteOne${objectNameCapitalized}Input!) { + deleteOne${objectNameCapitalized}(input: $input) { + id + } + } + `; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-many-metadata-query.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-many-metadata-query.factory.ts new file mode 100644 index 0000000000..7434b2eb30 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-many-metadata-query.factory.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; + +import { capitalize } from 'src/utils/capitalize'; +import { fetchMetadataFields } from 'src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils'; + +@Injectable() +export class FindManyMetadataQueryFactory { + create(objectNamePlural): string { + const fields = fetchMetadataFields(objectNamePlural); + + return ` + query FindMany${capitalize(objectNamePlural)}( + $paging: CursorPaging! + ) { + ${objectNamePlural}( + paging: $paging + ) { + edges { + node { + id + ${fields} + } + } + pageInfo { + hasNextPage + startCursor + endCursor + } + } + } + `; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-one-metadata-query.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-one-metadata-query.factory.ts new file mode 100644 index 0000000000..98078a29ef --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/find-one-metadata-query.factory.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; + +import { capitalize } from 'src/utils/capitalize'; +import { fetchMetadataFields } from 'src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils'; + +@Injectable() +export class FindOneMetadataQueryFactory { + create(objectNameSingular: string, objectNamePlural: string): string { + const fields = fetchMetadataFields(objectNamePlural); + + return ` + query FindOne${capitalize(objectNameSingular)}( + $id: UUID!, + ) { + ${objectNameSingular}(id: $id) { + id + ${fields} + } + } + `; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/get-metadata-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/get-metadata-variables.factory.ts new file mode 100644 index 0000000000..61149853b0 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/get-metadata-variables.factory.ts @@ -0,0 +1,42 @@ +import { BadRequestException, Injectable } from '@nestjs/common'; + +import { Request } from 'express'; + +import { LimitInputFactory } from 'src/engine/api/rest/input-factories/limit-input.factory'; +import { EndingBeforeInputFactory } from 'src/engine/api/rest/input-factories/ending-before-input.factory'; +import { StartingAfterInputFactory } from 'src/engine/api/rest/input-factories/starting-after-input.factory'; +import { MetadataQueryVariables } from 'src/engine/api/rest/metadata/types/metadata-query-variables.type'; + +@Injectable() +export class GetMetadataVariablesFactory { + constructor( + private readonly startingAfterInputFactory: StartingAfterInputFactory, + private readonly endingBeforeInputFactory: EndingBeforeInputFactory, + private readonly limitInputFactory: LimitInputFactory, + ) {} + + create(id: string | undefined, request: Request): MetadataQueryVariables { + if (id) { + return { id }; + } + + const limit = this.limitInputFactory.create(request, 1000); + const before = this.endingBeforeInputFactory.create(request); + const after = this.startingAfterInputFactory.create(request); + + if (before && after) { + throw new BadRequestException( + `Only one of 'endingBefore' and 'startingAfter' may be provided`, + ); + } + + return { + paging: { + first: !before ? limit : undefined, + last: before ? limit : undefined, + after, + before, + }, + }; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/metadata-factories.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/metadata-factories.ts new file mode 100644 index 0000000000..f8a7f48556 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/metadata-factories.ts @@ -0,0 +1,17 @@ +import { FindOneMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/find-one-metadata-query.factory'; +import { FindManyMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/find-many-metadata-query.factory'; +import { GetMetadataVariablesFactory } from 'src/engine/api/rest/metadata/query-builder/factories/get-metadata-variables.factory'; +import { inputFactories } from 'src/engine/api/rest/input-factories/factories'; +import { CreateMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/create-metadata-query.factory'; +import { UpdateMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/update-metadata-query.factory'; +import { DeleteMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/delete-metadata-query.factory'; + +export const metadataQueryBuilderFactories = [ + FindOneMetadataQueryFactory, + FindManyMetadataQueryFactory, + CreateMetadataQueryFactory, + DeleteMetadataQueryFactory, + UpdateMetadataQueryFactory, + GetMetadataVariablesFactory, + ...inputFactories, +]; diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/update-metadata-query.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/update-metadata-query.factory.ts new file mode 100644 index 0000000000..6be62fc48a --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/factories/update-metadata-query.factory.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; + +import { capitalize } from 'src/utils/capitalize'; +import { fetchMetadataFields } from 'src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils'; + +@Injectable() +export class UpdateMetadataQueryFactory { + create(objectNameSingular: string, objectNamePlural: string): string { + const objectNameCapitalized = capitalize(objectNameSingular); + + const fields = fetchMetadataFields(objectNamePlural); + + return ` + mutation Update${objectNameCapitalized}($input: UpdateOne${objectNameCapitalized}${ + objectNameSingular === 'field' ? 'Metadata' : '' + }Input!) { + updateOne${objectNameCapitalized}(input: $input) { + id + ${fields} + } + } + `; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.factory.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.factory.ts new file mode 100644 index 0000000000..ce9b38ce82 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.factory.ts @@ -0,0 +1,95 @@ +import { BadRequestException, Injectable } from '@nestjs/common'; + +import { Request } from 'express'; + +import { GetMetadataVariablesFactory } from 'src/engine/api/rest/metadata/query-builder/factories/get-metadata-variables.factory'; +import { FindOneMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/find-one-metadata-query.factory'; +import { FindManyMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/find-many-metadata-query.factory'; +import { parseMetadataPath } from 'src/engine/api/rest/metadata/query-builder/utils/parse-metadata-path.utils'; +import { CreateMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/create-metadata-query.factory'; +import { UpdateMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/update-metadata-query.factory'; +import { DeleteMetadataQueryFactory } from 'src/engine/api/rest/metadata/query-builder/factories/delete-metadata-query.factory'; +import { MetadataQuery } from 'src/engine/api/rest/metadata/types/metadata-query.type'; + +@Injectable() +export class MetadataQueryBuilderFactory { + constructor( + private readonly findOneQueryFactory: FindOneMetadataQueryFactory, + private readonly findManyQueryFactory: FindManyMetadataQueryFactory, + private readonly createQueryFactory: CreateMetadataQueryFactory, + private readonly updateQueryFactory: UpdateMetadataQueryFactory, + private readonly deleteQueryFactory: DeleteMetadataQueryFactory, + private readonly getMetadataVariablesFactory: GetMetadataVariablesFactory, + ) {} + + async get(request: Request): Promise { + const { id, objectNameSingular, objectNamePlural } = + parseMetadataPath(request); + + return { + query: id + ? this.findOneQueryFactory.create(objectNameSingular, objectNamePlural) + : this.findManyQueryFactory.create(objectNamePlural), + variables: this.getMetadataVariablesFactory.create(id, request), + }; + } + + async create(request: Request): Promise { + const { objectNameSingular, objectNamePlural } = parseMetadataPath(request); + + return { + query: this.createQueryFactory.create( + objectNameSingular, + objectNamePlural, + ), + variables: { + input: { + [objectNameSingular]: request.body, + }, + }, + }; + } + + async update(request: Request): Promise { + const { objectNameSingular, objectNamePlural, id } = + parseMetadataPath(request); + + if (!id) { + throw new BadRequestException( + `update ${objectNameSingular} query invalid. Id missing. eg: /rest/metadata/${objectNameSingular}/0d4389ef-ea9c-4ae8-ada1-1cddc440fb56`, + ); + } + + return { + query: this.updateQueryFactory.create( + objectNameSingular, + objectNamePlural, + ), + variables: { + input: { + update: request.body, + id, + }, + }, + }; + } + + async delete(request: Request): Promise { + const { objectNameSingular, id } = parseMetadataPath(request); + + if (!id) { + throw new BadRequestException( + `delete ${objectNameSingular} query invalid. Id missing. eg: /rest/metadata/${objectNameSingular}/0d4389ef-ea9c-4ae8-ada1-1cddc440fb56`, + ); + } + + return { + query: this.deleteQueryFactory.create(objectNameSingular), + variables: { + input: { + id, + }, + }, + }; + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.module.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.module.ts new file mode 100644 index 0000000000..82bf0fb567 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/metadata-query-builder.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; + +import { AuthModule } from 'src/engine/core-modules/auth/auth.module'; +import { MetadataQueryBuilderFactory } from 'src/engine/api/rest/metadata/query-builder/metadata-query-builder.factory'; +import { metadataQueryBuilderFactories } from 'src/engine/api/rest/metadata/query-builder/factories/metadata-factories'; + +@Module({ + imports: [AuthModule], + providers: [...metadataQueryBuilderFactories, MetadataQueryBuilderFactory], + exports: [MetadataQueryBuilderFactory], +}) +export class MetadataQueryBuilderModule {} diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-metadata-path.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/__tests__/parse-metadata-path.utils.spec.ts similarity index 90% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-metadata-path.utils.spec.ts rename to packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/__tests__/parse-metadata-path.utils.spec.ts index 28b1238c24..ec6284da77 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/__tests__/parse-metadata-path.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/__tests__/parse-metadata-path.utils.spec.ts @@ -1,4 +1,4 @@ -import { parseMetadataPath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-metadata-path.utils'; +import { parseMetadataPath } from 'src/engine/api/rest/metadata/query-builder/utils/parse-metadata-path.utils'; describe('parseMetadataPath', () => { it('should parse object from request path with uuid', () => { diff --git a/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils.ts new file mode 100644 index 0000000000..61899096d2 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/fetch-metadata-fields.utils.ts @@ -0,0 +1,93 @@ +export const fetchMetadataFields = (objectNamePlural: string) => { + const fields = ` + type + name + label + description + icon + isCustom + isActive + isSystem + isNullable + createdAt + updatedAt + fromRelationMetadata { + id + relationType + toObjectMetadata { + id + dataSourceId + nameSingular + namePlural + isSystem + } + toFieldMetadataId + } + toRelationMetadata { + id + relationType + fromObjectMetadata { + id + dataSourceId + nameSingular + namePlural + isSystem + } + fromFieldMetadataId + } + defaultValue + options + `; + + switch (objectNamePlural) { + case 'objects': + return ` + dataSourceId + nameSingular + namePlural + labelSingular + labelPlural + description + icon + isCustom + isActive + isSystem + createdAt + updatedAt + labelIdentifierFieldMetadataId + imageIdentifierFieldMetadataId + fields(paging: { first: 1000 }) { + edges { + node { + id + ${fields} + } + } + } + `; + case 'fields': + return fields; + case 'relations': + return ` + relationType + fromObjectMetadata { + id + dataSourceId + nameSingular + namePlural + isSystem + } + fromObjectMetadataId + toObjectMetadata { + id + dataSourceId + nameSingular + namePlural + isSystem + } + toObjectMetadataId + fromFieldMetadataId + toFieldMetadataId + `; + } +}; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-metadata-path.utils.ts b/packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/parse-metadata-path.utils.ts similarity index 100% rename from packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-metadata-path.utils.ts rename to packages/twenty-server/src/engine/api/rest/metadata/query-builder/utils/parse-metadata-path.utils.ts diff --git a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-metadata.controller.ts b/packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.controller.ts similarity index 94% rename from packages/twenty-server/src/engine/api/rest/controllers/rest-api-metadata.controller.ts rename to packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.controller.ts index fc44d8bc96..fc0154081f 100644 --- a/packages/twenty-server/src/engine/api/rest/controllers/rest-api-metadata.controller.ts +++ b/packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.controller.ts @@ -11,7 +11,7 @@ import { import { Request, Response } from 'express'; -import { RestApiMetadataService } from 'src/engine/api/rest/services/rest-api-metadata.service'; +import { RestApiMetadataService } from 'src/engine/api/rest/metadata/rest-api-metadata.service'; import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils'; @Controller('rest/metadata/*') diff --git a/packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.service.ts b/packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.service.ts new file mode 100644 index 0000000000..afd0e59efd --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/rest-api-metadata.service.ts @@ -0,0 +1,63 @@ +import { Injectable } from '@nestjs/common'; + +import { Request } from 'express'; + +import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; +import { + GraphqlApiType, + RestApiService, +} from 'src/engine/api/rest/rest-api.service'; +import { MetadataQueryBuilderFactory } from 'src/engine/api/rest/metadata/query-builder/metadata-query-builder.factory'; + +@Injectable() +export class RestApiMetadataService { + constructor( + private readonly tokenService: TokenService, + private readonly metadataQueryBuilderFactory: MetadataQueryBuilderFactory, + private readonly restApiService: RestApiService, + ) {} + + async get(request: Request) { + await this.tokenService.validateToken(request); + const data = await this.metadataQueryBuilderFactory.get(request); + + return await this.restApiService.call( + GraphqlApiType.METADATA, + request, + data, + ); + } + + async create(request: Request) { + await this.tokenService.validateToken(request); + const data = await this.metadataQueryBuilderFactory.create(request); + + return await this.restApiService.call( + GraphqlApiType.METADATA, + request, + data, + ); + } + + async update(request: Request) { + await this.tokenService.validateToken(request); + const data = await this.metadataQueryBuilderFactory.update(request); + + return await this.restApiService.call( + GraphqlApiType.METADATA, + request, + data, + ); + } + + async delete(request: Request) { + await this.tokenService.validateToken(request); + const data = await this.metadataQueryBuilderFactory.delete(request); + + return await this.restApiService.call( + GraphqlApiType.METADATA, + request, + data, + ); + } +} diff --git a/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query-variables.type.ts b/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query-variables.type.ts new file mode 100644 index 0000000000..edc86f56fb --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query-variables.type.ts @@ -0,0 +1,10 @@ +export type MetadataQueryVariables = { + id?: string; + input?: object; + paging?: { + first?: number; + last?: number; + after?: string; + before?: string; + }; +}; diff --git a/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query.type.ts b/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query.type.ts new file mode 100644 index 0000000000..6a33424823 --- /dev/null +++ b/packages/twenty-server/src/engine/api/rest/metadata/types/metadata-query.type.ts @@ -0,0 +1,6 @@ +import { MetadataQueryVariables } from 'src/engine/api/rest/metadata/types/metadata-query-variables.type'; + +export type MetadataQuery = { + query: string; + variables: MetadataQueryVariables; +}; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/__tests__/core-query-builder.factory.spec.ts b/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/__tests__/core-query-builder.factory.spec.ts deleted file mode 100644 index b641974171..0000000000 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/__tests__/core-query-builder.factory.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; - -import { CoreQueryBuilderFactory } from 'src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory'; -import { DeleteQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-query.factory'; -import { CreateOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory'; -import { CreateManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory'; -import { UpdateQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory'; -import { FindOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory'; -import { FindManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory'; -import { DeleteVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory'; -import { CreateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory'; -import { UpdateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory'; -import { GetVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory'; -import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service'; -import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; -import { EnvironmentService } from 'src/engine/integrations/environment/environment.service'; - -describe('CoreQueryBuilderFactory', () => { - let service: CoreQueryBuilderFactory; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - CoreQueryBuilderFactory, - { provide: DeleteQueryFactory, useValue: {} }, - { provide: CreateOneQueryFactory, useValue: {} }, - { provide: CreateManyQueryFactory, useValue: {} }, - { provide: UpdateQueryFactory, useValue: {} }, - { provide: FindOneQueryFactory, useValue: {} }, - { provide: FindManyQueryFactory, useValue: {} }, - { provide: DeleteVariablesFactory, useValue: {} }, - { provide: CreateVariablesFactory, useValue: {} }, - { provide: UpdateVariablesFactory, useValue: {} }, - { provide: GetVariablesFactory, useValue: {} }, - { provide: ObjectMetadataService, useValue: {} }, - { provide: TokenService, useValue: {} }, - { provide: EnvironmentService, useValue: {} }, - ], - }).compile(); - - service = module.get(CoreQueryBuilderFactory); - }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/factories.ts b/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/factories.ts deleted file mode 100644 index d583d2dfdf..0000000000 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/factories.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { DeleteQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-query.factory'; -import { CreateOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-one-query.factory'; -import { UpdateQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-query.factory'; -import { FindOneQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-one-query.factory'; -import { FindManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/find-many-query.factory'; -import { DeleteVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/delete-variables.factory'; -import { CreateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-variables.factory'; -import { UpdateVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/update-variables.factory'; -import { GetVariablesFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory'; -import { LimitInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory'; -import { OrderByInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory'; -import { FilterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory'; -import { CreateManyQueryFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/create-many-query.factory'; -import { StartingAfterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/starting-after-input.factory'; -import { EndingBeforeInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/ending-before-input.factory'; - -export const coreQueryBuilderFactories = [ - DeleteQueryFactory, - CreateOneQueryFactory, - CreateManyQueryFactory, - UpdateQueryFactory, - FindOneQueryFactory, - FindManyQueryFactory, - DeleteVariablesFactory, - CreateVariablesFactory, - UpdateVariablesFactory, - GetVariablesFactory, - StartingAfterInputFactory, - EndingBeforeInputFactory, - LimitInputFactory, - OrderByInputFactory, - FilterInputFactory, -]; diff --git a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory.ts b/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory.ts deleted file mode 100644 index 8703e67f7f..0000000000 --- a/packages/twenty-server/src/engine/api/rest/rest-api-core-query-builder/factories/get-variables.factory.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -import { Request } from 'express'; - -import { LimitInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/limit-input.factory'; -import { OrderByInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory'; -import { FilterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-input.factory'; -import { QueryVariables } from 'src/engine/api/rest/types/query-variables.type'; -import { EndingBeforeInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/ending-before-input.factory'; -import { StartingAfterInputFactory } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/starting-after-input.factory'; - -@Injectable() -export class GetVariablesFactory { - constructor( - private readonly startingAfterInputFactory: StartingAfterInputFactory, - private readonly endingBeforeInputFactory: EndingBeforeInputFactory, - private readonly limitInputFactory: LimitInputFactory, - private readonly orderByInputFactory: OrderByInputFactory, - private readonly filterInputFactory: FilterInputFactory, - ) {} - - create( - id: string | undefined, - request: Request, - objectMetadata, - ): QueryVariables { - if (id) { - return { filter: { id: { eq: id } } }; - } - - return { - filter: this.filterInputFactory.create(request, objectMetadata), - orderBy: this.orderByInputFactory.create(request, objectMetadata), - limit: this.limitInputFactory.create(request), - startingAfter: this.startingAfterInputFactory.create(request), - endingBefore: this.endingBeforeInputFactory.create(request), - }; - } -} diff --git a/packages/twenty-server/src/engine/api/rest/rest-api.module.ts b/packages/twenty-server/src/engine/api/rest/rest-api.module.ts index 16141805d5..c459f32862 100644 --- a/packages/twenty-server/src/engine/api/rest/rest-api.module.ts +++ b/packages/twenty-server/src/engine/api/rest/rest-api.module.ts @@ -1,23 +1,39 @@ import { Module } from '@nestjs/common'; import { HttpModule } from '@nestjs/axios'; -import { RestApiCoreController } from 'src/engine/api/rest/controllers/rest-api-core.controller'; -import { RestApiCoreService } from 'src/engine/api/rest/services/rest-api-core.service'; -import { CoreQueryBuilderModule } from 'src/engine/api/rest/rest-api-core-query-builder/core-query-builder.module'; +import { RestApiCoreController } from 'src/engine/api/rest/core/controllers/rest-api-core.controller'; +import { RestApiCoreService } from 'src/engine/api/rest/core/rest-api-core.service'; +import { CoreQueryBuilderModule } from 'src/engine/api/rest/core/query-builder/core-query-builder.module'; import { AuthModule } from 'src/engine/core-modules/auth/auth.module'; -import { RestApiMetadataController } from 'src/engine/api/rest/controllers/rest-api-metadata.controller'; -import { RestApiMetadataService } from 'src/engine/api/rest/services/rest-api-metadata.service'; -import { RestApiCoreBatchController } from 'src/engine/api/rest/controllers/rest-api-core-batch.controller'; -import { RestApiService } from 'src/engine/api/rest/services/rest-api.service'; +import { RestApiMetadataController } from 'src/engine/api/rest/metadata/rest-api-metadata.controller'; +import { RestApiMetadataService } from 'src/engine/api/rest/metadata/rest-api-metadata.service'; +import { RestApiCoreBatchController } from 'src/engine/api/rest/core/controllers/rest-api-core-batch.controller'; +import { RestApiService } from 'src/engine/api/rest/rest-api.service'; +import { EndingBeforeInputFactory } from 'src/engine/api/rest/input-factories/ending-before-input.factory'; +import { LimitInputFactory } from 'src/engine/api/rest/input-factories/limit-input.factory'; +import { StartingAfterInputFactory } from 'src/engine/api/rest/input-factories/starting-after-input.factory'; +import { MetadataQueryBuilderModule } from 'src/engine/api/rest/metadata/query-builder/metadata-query-builder.module'; @Module({ - imports: [CoreQueryBuilderModule, AuthModule, HttpModule], + imports: [ + CoreQueryBuilderModule, + MetadataQueryBuilderModule, + AuthModule, + HttpModule, + ], controllers: [ RestApiMetadataController, RestApiCoreBatchController, RestApiCoreController, ], - providers: [RestApiMetadataService, RestApiCoreService, RestApiService], + providers: [ + RestApiMetadataService, + RestApiCoreService, + RestApiService, + StartingAfterInputFactory, + EndingBeforeInputFactory, + LimitInputFactory, + ], exports: [RestApiMetadataService], }) export class RestApiModule {} diff --git a/packages/twenty-server/src/engine/api/rest/services/rest-api.service.ts b/packages/twenty-server/src/engine/api/rest/rest-api.service.ts similarity index 95% rename from packages/twenty-server/src/engine/api/rest/services/rest-api.service.ts rename to packages/twenty-server/src/engine/api/rest/rest-api.service.ts index 1107a25981..d6b4d21640 100644 --- a/packages/twenty-server/src/engine/api/rest/services/rest-api.service.ts +++ b/packages/twenty-server/src/engine/api/rest/rest-api.service.ts @@ -4,7 +4,7 @@ import { HttpService } from '@nestjs/axios'; import { Request } from 'express'; import { AxiosResponse } from 'axios'; -import { Query } from 'src/engine/api/rest/types/query.type'; +import { Query } from 'src/engine/api/rest/core/types/query.type'; import { getServerUrl } from 'src/utils/get-server-url'; import { EnvironmentService } from 'src/engine/integrations/environment/environment.service'; import { RestApiException } from 'src/engine/api/rest/errors/RestApiException'; diff --git a/packages/twenty-server/src/engine/api/rest/services/__tests__/core.service.spec.ts b/packages/twenty-server/src/engine/api/rest/services/__tests__/core.service.spec.ts deleted file mode 100644 index 45fde1dfdc..0000000000 --- a/packages/twenty-server/src/engine/api/rest/services/__tests__/core.service.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; - -import { RestApiCoreService } from 'src/engine/api/rest/services/rest-api-core.service'; -import { CoreQueryBuilderFactory } from 'src/engine/api/rest/rest-api-core-query-builder/core-query-builder.factory'; -import { RestApiService } from 'src/engine/api/rest/services/rest-api.service'; - -describe('RestApiCoreService', () => { - let service: RestApiCoreService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - RestApiCoreService, - { - provide: CoreQueryBuilderFactory, - useValue: {}, - }, - { - provide: RestApiService, - useValue: {}, - }, - ], - }).compile(); - - service = module.get(RestApiCoreService); - }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/packages/twenty-server/src/engine/api/rest/services/rest-api-metadata.service.ts b/packages/twenty-server/src/engine/api/rest/services/rest-api-metadata.service.ts deleted file mode 100644 index b16bc50f03..0000000000 --- a/packages/twenty-server/src/engine/api/rest/services/rest-api-metadata.service.ts +++ /dev/null @@ -1,290 +0,0 @@ -import { BadRequestException, Injectable } from '@nestjs/common'; - -import { Query } from 'src/engine/api/rest/types/query.type'; -import { TokenService } from 'src/engine/core-modules/auth/services/token.service'; -import { capitalize } from 'src/utils/capitalize'; -import { parseMetadataPath } from 'src/engine/api/rest/rest-api-core-query-builder/utils/path-parsers/parse-metadata-path.utils'; -import { - GraphqlApiType, - RestApiService, -} from 'src/engine/api/rest/services/rest-api.service'; - -@Injectable() -export class RestApiMetadataService { - constructor( - private readonly tokenService: TokenService, - private readonly restApiService: RestApiService, - ) {} - - fetchMetadataFields(objectNamePlural: string) { - const fields = ` - type - name - label - description - icon - isCustom - isActive - isSystem - isNullable - createdAt - updatedAt - fromRelationMetadata { - id - relationType - toObjectMetadata { - id - dataSourceId - nameSingular - namePlural - isSystem - } - toFieldMetadataId - } - toRelationMetadata { - id - relationType - fromObjectMetadata { - id - dataSourceId - nameSingular - namePlural - isSystem - } - fromFieldMetadataId - } - defaultValue - options - `; - - switch (objectNamePlural) { - case 'objects': - return ` - dataSourceId - nameSingular - namePlural - labelSingular - labelPlural - description - icon - isCustom - isActive - isSystem - createdAt - updatedAt - labelIdentifierFieldMetadataId - imageIdentifierFieldMetadataId - fields(paging: { first: 1000 }) { - edges { - node { - id - ${fields} - } - } - } - `; - case 'fields': - return fields; - case 'relations': - return ` - relationType - fromObjectMetadata { - id - dataSourceId - nameSingular - namePlural - isSystem - } - fromObjectMetadataId - toObjectMetadata { - id - dataSourceId - nameSingular - namePlural - isSystem - } - toObjectMetadataId - fromFieldMetadataId - toFieldMetadataId - `; - } - } - - generateFindManyQuery(objectNameSingular: string, objectNamePlural: string) { - const fields = this.fetchMetadataFields(objectNamePlural); - - let filterType = ''; - let filterValue = ''; - - if (objectNamePlural !== 'relations') { - filterType = `($filter: ${objectNameSingular}Filter)`; - filterValue = 'filter: $filter,'; - } - - return ` - query FindMany${capitalize(objectNamePlural)}${filterType} { - ${objectNamePlural}( - ${filterValue} - paging: { first: 1000 } - ) { - edges { - node { - id - ${fields} - } - } - } - } - `; - } - - generateFindOneQuery(objectNameSingular: string, objectNamePlural: string) { - const fields = this.fetchMetadataFields(objectNamePlural); - - return ` - query FindOne${capitalize(objectNameSingular)}( - $id: UUID!, - ) { - ${objectNameSingular}(id: $id) { - id - ${fields} - } - } - `; - } - - async get(request) { - await this.tokenService.validateToken(request); - - const { objectNameSingular, objectNamePlural, id } = - parseMetadataPath(request); - - const query = id - ? this.generateFindOneQuery(objectNameSingular, objectNamePlural) - : this.generateFindManyQuery(objectNameSingular, objectNamePlural); - - const data: Query = { - query, - variables: id ? { id } : request.body, - }; - - return await this.restApiService.call( - GraphqlApiType.METADATA, - request, - data, - ); - } - - async create(request) { - await this.tokenService.validateToken(request); - - const { objectNameSingular: objectName, objectNamePlural } = - parseMetadataPath(request); - const objectNameCapitalized = capitalize(objectName); - - const fields = this.fetchMetadataFields(objectNamePlural); - - const query = ` - mutation Create${objectNameCapitalized}($input: CreateOne${objectNameCapitalized}Input!) { - createOne${objectNameCapitalized}(input: $input) { - id - ${fields} - } - } - `; - - const data: Query = { - query, - variables: { - input: { - [objectName]: request.body, - }, - }, - }; - - return await this.restApiService.call( - GraphqlApiType.METADATA, - request, - data, - ); - } - - async update(request) { - await this.tokenService.validateToken(request); - - const { - objectNameSingular: objectName, - objectNamePlural, - id, - } = parseMetadataPath(request); - const objectNameCapitalized = capitalize(objectName); - - if (!id) { - throw new BadRequestException( - `update ${objectName} query invalid. Id missing. eg: /rest/metadata/${objectName}/0d4389ef-ea9c-4ae8-ada1-1cddc440fb56`, - ); - } - const fields = this.fetchMetadataFields(objectNamePlural); - - const query = ` - mutation Update${objectNameCapitalized}($input: UpdateOne${objectNameCapitalized}Input!) { - updateOne${objectNameCapitalized}(input: $input) { - id - ${fields} - } - } - `; - - const data: Query = { - query, - variables: { - input: { - update: request.body, - id, - }, - }, - }; - - return await this.restApiService.call( - GraphqlApiType.METADATA, - request, - data, - ); - } - - async delete(request) { - await this.tokenService.validateToken(request); - - const { objectNameSingular: objectName, id } = parseMetadataPath(request); - const objectNameCapitalized = capitalize(objectName); - - if (!id) { - throw new BadRequestException( - `delete ${objectName} query invalid. Id missing. eg: /rest/metadata/${objectName}/0d4389ef-ea9c-4ae8-ada1-1cddc440fb56`, - ); - } - - const query = ` - mutation Delete${objectNameCapitalized}($input: DeleteOne${objectNameCapitalized}Input!) { - deleteOne${objectNameCapitalized}(input: $input) { - id - } - } - `; - - const data: Query = { - query, - variables: { - input: { - id, - }, - }, - }; - - return await this.restApiService.call( - GraphqlApiType.METADATA, - request, - data, - ); - } -} diff --git a/packages/twenty-server/src/engine/api/rest/types/query.type.ts b/packages/twenty-server/src/engine/api/rest/types/query.type.ts deleted file mode 100644 index 1af013c8a1..0000000000 --- a/packages/twenty-server/src/engine/api/rest/types/query.type.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { QueryVariables } from 'src/engine/api/rest/types/query-variables.type'; - -export type Query = { - query: string; - variables: QueryVariables; -}; diff --git a/packages/twenty-server/src/engine/core-modules/open-api/open-api.service.ts b/packages/twenty-server/src/engine/core-modules/open-api/open-api.service.ts index 7ca67df1a8..8a3738b2a6 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/open-api.service.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/open-api.service.ts @@ -133,12 +133,13 @@ export class OpenApiService { get: { tags: [item.namePlural], summary: `Find Many ${item.namePlural}`, - parameters: - item.namePlural !== 'relations' - ? [{ $ref: '#/components/parameters/filter' }] - : undefined, + parameters: [ + { $ref: '#/components/parameters/limit' }, + { $ref: '#/components/parameters/startingAfter' }, + { $ref: '#/components/parameters/endingBefore' }, + ], responses: { - '200': getFindManyResponse200(item), + '200': getFindManyResponse200(item, true), '400': { $ref: '#/components/responses/400' }, '401': { $ref: '#/components/responses/401' }, }, @@ -161,7 +162,7 @@ export class OpenApiService { summary: `Find One ${item.nameSingular}`, parameters: [{ $ref: '#/components/parameters/idPath' }], responses: { - '200': getFindOneResponse200(item), + '200': getFindOneResponse200(item, true), '400': { $ref: '#/components/responses/400' }, '401': { $ref: '#/components/responses/401' }, }, @@ -177,18 +178,20 @@ export class OpenApiService { '401': { $ref: '#/components/responses/401' }, }, }, - patch: { - tags: [item.namePlural], - summary: `Update One ${item.namePlural}`, - operationId: `updateOne${capitalize(item.nameSingular)}`, - parameters: [{ $ref: '#/components/parameters/idPath' }], - requestBody: getRequestBody(capitalize(item.nameSingular)), - responses: { - '200': getUpdateOneResponse200(item, true), - '400': { $ref: '#/components/responses/400' }, - '401': { $ref: '#/components/responses/401' }, + ...(item.nameSingular !== 'relation' && { + patch: { + tags: [item.namePlural], + summary: `Update One ${item.nameSingular}`, + operationId: `updateOne${capitalize(item.nameSingular)}`, + parameters: [{ $ref: '#/components/parameters/idPath' }], + requestBody: getRequestBody(capitalize(item.nameSingular)), + responses: { + '200': getUpdateOneResponse200(item, true), + '400': { $ref: '#/components/responses/400' }, + '401': { $ref: '#/components/responses/401' }, + }, }, - }, + }), } as OpenAPIV3_1.PathItemObject; return path; @@ -197,7 +200,7 @@ export class OpenApiService { schema.components = { ...schema.components, // components.securitySchemes is defined in base Schema schemas: computeMetadataSchemaComponents(metadata), - parameters: computeParameterComponents(), + parameters: computeParameterComponents(true), responses: { '400': get400ErrorResponses(), '401': get401ErrorResponses(), diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/parameters.utils.spec.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/parameters.utils.spec.ts index 3fd99913c9..fd1cf3dde9 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/parameters.utils.spec.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/parameters.utils.spec.ts @@ -9,10 +9,10 @@ import { computeOrderByParameters, computeStartingAfterParameters, } from 'src/engine/core-modules/open-api/utils/parameters.utils'; -import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory'; -import { FilterComparators } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils'; -import { Conjunctions } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils'; -import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils'; +import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/input-factories/order-by-input.factory'; +import { FilterComparators } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils'; +import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils'; +import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils'; describe('computeParameters', () => { describe('computeLimit', () => { diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts index cc459639b4..3bdc3a9fad 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts @@ -218,10 +218,9 @@ export const computeSchemaComponents = ( ); }; -export const computeParameterComponents = (): Record< - string, - OpenAPIV3_1.ParameterObject -> => { +export const computeParameterComponents = ( + fromMetadata = false, +): Record => { return { idPath: computeIdPathParameter(), startingAfter: computeStartingAfterParameters(), @@ -229,7 +228,7 @@ export const computeParameterComponents = (): Record< filter: computeFilterParameters(), depth: computeDepthParameters(), orderBy: computeOrderByParameters(), - limit: computeLimitParameters(), + limit: computeLimitParameters(fromMetadata), }; }; @@ -240,7 +239,7 @@ export const computeMetadataSchemaComponents = ( (schemas, item) => { switch (item.nameSingular) { case 'object': { - schemas[`${capitalize(item.nameSingular)} with Relations`] = { + schemas[`${capitalize(item.nameSingular)}`] = { type: 'object', description: `An object`, properties: { @@ -290,7 +289,7 @@ export const computeMetadataSchemaComponents = ( return schemas; } case 'field': { - schemas[`${capitalize(item.nameSingular)} with Relations`] = { + schemas[`${capitalize(item.nameSingular)}`] = { type: 'object', description: `A field`, properties: { @@ -358,7 +357,7 @@ export const computeMetadataSchemaComponents = ( return schemas; } case 'relation': { - schemas[`${capitalize(item.nameSingular)} with Relations`] = { + schemas[`${capitalize(item.nameSingular)}`] = { type: 'object', description: 'A relation', properties: { diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/parameters.utils.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/parameters.utils.ts index b07c297e0d..de96442078 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/parameters.utils.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/parameters.utils.ts @@ -2,12 +2,14 @@ import { OpenAPIV3_1 } from 'openapi-types'; import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface'; -import { FilterComparators } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils'; -import { Conjunctions } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-filter.utils'; -import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory'; -import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/add-default-conjunction.utils'; +import { FilterComparators } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-base-filter.utils'; +import { Conjunctions } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/parse-filter.utils'; +import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/input-factories/order-by-input.factory'; +import { DEFAULT_CONJUNCTION } from 'src/engine/api/rest/core/query-builder/utils/filter-utils/add-default-conjunction.utils'; -export const computeLimitParameters = (): OpenAPIV3_1.ParameterObject => { +export const computeLimitParameters = ( + fromMetadata = false, +): OpenAPIV3_1.ParameterObject => { return { name: 'limit', in: 'query', @@ -16,8 +18,8 @@ export const computeLimitParameters = (): OpenAPIV3_1.ParameterObject => { schema: { type: 'integer', minimum: 0, - maximum: 60, - default: 60, + maximum: fromMetadata ? 1000 : 60, + default: fromMetadata ? 1000 : 60, }, }; }; diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/path.utils.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/path.utils.ts index 37b1e217a4..fb73fb5ecb 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/path.utils.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/path.utils.ts @@ -105,7 +105,7 @@ export const computeSingleResultPath = ( }, patch: { tags: [item.namePlural], - summary: `Update One ${item.namePlural}`, + summary: `Update One ${item.nameSingular}`, operationId: `UpdateOne${capitalize(item.nameSingular)}`, parameters: [ { $ref: '#/components/parameters/idPath' }, diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/responses.utils.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/responses.utils.ts index 7793a507f8..49264fee0e 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/responses.utils.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/responses.utils.ts @@ -3,6 +3,7 @@ import { capitalize } from 'src/utils/capitalize'; export const getFindManyResponse200 = ( item: Pick, + fromMetadata = false, ) => { return { description: 'Successful operation', @@ -19,7 +20,7 @@ export const getFindManyResponse200 = ( items: { $ref: `#/components/schemas/${capitalize( item.nameSingular, - )} with Relations`, + )}${!fromMetadata ? ' with Relations' : ''}`, }, }, }, @@ -32,9 +33,11 @@ export const getFindManyResponse200 = ( endCursor: { type: 'string' }, }, }, - totalCount: { - type: 'integer', - }, + ...(!fromMetadata && { + totalCount: { + type: 'integer', + }, + }), }, example: { data: { @@ -59,6 +62,7 @@ export const getFindManyResponse200 = ( export const getFindOneResponse200 = ( item: Pick, + fromMetadata = false, ) => { return { description: 'Successful operation', @@ -71,9 +75,9 @@ export const getFindOneResponse200 = ( type: 'object', properties: { [item.nameSingular]: { - $ref: `#/components/schemas/${capitalize( - item.nameSingular, - )} with Relations`, + $ref: `#/components/schemas/${capitalize(item.nameSingular)}${ + !fromMetadata ? ' with Relations' : '' + }`, }, }, },