diff --git a/packages/twenty-server/src/constants/settings/index.ts b/packages/twenty-server/src/constants/settings/index.ts index f3004a2807..fadc116d7c 100644 --- a/packages/twenty-server/src/constants/settings/index.ts +++ b/packages/twenty-server/src/constants/settings/index.ts @@ -9,4 +9,5 @@ export const settings: Settings = { }, maxFileSize: '10MB', }, + minLengthOfStringForDuplicateCheck: 3, }; diff --git a/packages/twenty-server/src/constants/settings/interfaces/settings.interface.ts b/packages/twenty-server/src/constants/settings/interfaces/settings.interface.ts index 472c3b3b55..c268aff280 100644 --- a/packages/twenty-server/src/constants/settings/interfaces/settings.interface.ts +++ b/packages/twenty-server/src/constants/settings/interfaces/settings.interface.ts @@ -11,4 +11,5 @@ export interface Settings { }; maxFileSize: `${number}MB`; }; + minLengthOfStringForDuplicateCheck: number; } diff --git a/packages/twenty-server/src/workspace/workspace-query-builder/factories/__tests__/find-duplicates-query.factory.spec.ts b/packages/twenty-server/src/workspace/workspace-query-builder/factories/__tests__/find-duplicates-query.factory.spec.ts index 96472a36d9..bae840648c 100644 --- a/packages/twenty-server/src/workspace/workspace-query-builder/factories/__tests__/find-duplicates-query.factory.spec.ts +++ b/packages/twenty-server/src/workspace/workspace-query-builder/factories/__tests__/find-duplicates-query.factory.spec.ts @@ -81,7 +81,35 @@ describe('FindDuplicatesQueryFactory', () => { }); expect(query.trim()).toEqual(`query { - personCollection(filter: {or:[{nameFirstName:{ilike:\"%John%\"},nameLastName:{ilike:\"%Doe%\"}}]}) { + personCollection(filter: {or:[{nameFirstName:{eq:\"John\"},nameLastName:{eq:\"Doe\"}}]}) { + fieldsString + } + }`); + }); + + it('should ignore an argument if the string length is less than 3', async () => { + argAliasCreate.mockReturnValue({ + linkedinLinkUrl: 'ab', + email: 'test@test.com', + }); + + const args: FindDuplicatesResolverArgs = { + data: { + linkedinLinkUrl: 'ab', + email: 'test@test.com', + } as unknown as RecordFilter, + }; + + const query = await service.create(args, { + ...workspaceQueryBuilderOptions, + objectMetadataItem: { + ...workspaceQueryBuilderOptions.objectMetadataItem, + nameSingular: 'person', + }, + }); + + expect(query.trim()).toEqual(`query { + personCollection(filter: {or:[{email:{eq:"test@test.com"}}]}) { fieldsString } }`); @@ -140,7 +168,7 @@ describe('FindDuplicatesQueryFactory', () => { ); expect(query.trim()).toEqual(`query { - personCollection(filter: {id:{neq:\"uuid\"},or:[{nameFirstName:{ilike:\"%Peter%\"},nameLastName:{ilike:\"%Parker%\"}}]}) { + personCollection(filter: {id:{neq:\"uuid\"},or:[{nameFirstName:{eq:\"Peter\"},nameLastName:{eq:\"Parker\"}}]}) { fieldsString } }`); diff --git a/packages/twenty-server/src/workspace/workspace-query-builder/factories/find-duplicates-query.factory.ts b/packages/twenty-server/src/workspace/workspace-query-builder/factories/find-duplicates-query.factory.ts index b5bf98fc7a..ad2ea30b0f 100644 --- a/packages/twenty-server/src/workspace/workspace-query-builder/factories/find-duplicates-query.factory.ts +++ b/packages/twenty-server/src/workspace/workspace-query-builder/factories/find-duplicates-query.factory.ts @@ -11,6 +11,7 @@ import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-tar import { stringifyWithoutKeyQuote } from 'src/workspace/workspace-query-builder/utils/stringify-without-key-quote.util'; import { ArgsAliasFactory } from 'src/workspace/workspace-query-builder/factories/args-alias.factory'; import { duplicateCriteriaCollection } from 'src/workspace/workspace-resolver-builder/constants/duplicate-criteria.constants'; +import { settings } from 'src/constants/settings'; import { FieldsStringFactory } from './fields-string.factory'; @@ -113,14 +114,20 @@ export class FindDuplicatesQueryFactory { this.getApplicableDuplicateCriteriaCollection(objectMetadataItem); const criteriaWithMatchingArgs = criteriaCollection.filter((criteria) => - criteria.columnNames.every((columnName) => !!argsData[columnName]), + criteria.columnNames.every((columnName) => { + const value = argsData[columnName] as string | undefined; + + return ( + !!value && value.length >= settings.minLengthOfStringForDuplicateCheck + ); + }), ); const filterCriteria = criteriaWithMatchingArgs.map((criteria) => Object.fromEntries( criteria.columnNames.map((columnName) => [ columnName, - { ilike: `%${argsData[columnName]}%` }, + { eq: argsData[columnName] }, ]), ), );