feat: change condition of duplicate check (#4273)

* change condition of duplicate check

* fix: review comments addressed
This commit is contained in:
rostaklein 2024-03-05 12:11:37 +01:00 committed by GitHub
parent 91e5e7598b
commit f2099d339f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 4 deletions

View File

@ -9,4 +9,5 @@ export const settings: Settings = {
},
maxFileSize: '10MB',
},
minLengthOfStringForDuplicateCheck: 3,
};

View File

@ -11,4 +11,5 @@ export interface Settings {
};
maxFileSize: `${number}MB`;
};
minLengthOfStringForDuplicateCheck: number;
}

View File

@ -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
}
}`);

View File

@ -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] },
]),
),
);