mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-25 13:02:15 +03:00
feat: change condition of duplicate check (#4273)
* change condition of duplicate check * fix: review comments addressed
This commit is contained in:
parent
91e5e7598b
commit
f2099d339f
@ -9,4 +9,5 @@ export const settings: Settings = {
|
||||
},
|
||||
maxFileSize: '10MB',
|
||||
},
|
||||
minLengthOfStringForDuplicateCheck: 3,
|
||||
};
|
||||
|
@ -11,4 +11,5 @@ export interface Settings {
|
||||
};
|
||||
maxFileSize: `${number}MB`;
|
||||
};
|
||||
minLengthOfStringForDuplicateCheck: number;
|
||||
}
|
||||
|
@ -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<RecordFilter> = {
|
||||
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
|
||||
}
|
||||
}`);
|
||||
|
@ -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] },
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user