Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-10-11 04:25:59 +00:00
commit e61755182c
2 changed files with 29 additions and 0 deletions

View File

@ -167,6 +167,8 @@ describe('transformToFilter', () => {
if (name === `${collectionName}.field1`) return {};
if (name === `${collectionName}.field2`) return {};
if (name === `${collectionName}.field3`) return { target: 'targetCollection', targetKey: 'id' };
if (name === `${collectionName}.chinaRegion`)
return { target: 'chinaRegions', targetKey: 'code', interface: 'chinaRegion' };
return {};
});
@ -242,4 +244,27 @@ describe('transformToFilter', () => {
expect(filter).toEqual(expectedFilter);
});
it('should handle chinaRegion', () => {
const values = {
chinaRegion: [
{
code: '1',
},
{
code: '2',
},
{
code: '3',
},
],
};
const expectedFilter = {
$and: [{ 'chinaRegion.code': { $eq: '3' } }],
};
const filter = transformToFilter(values, operators, getCollectionJoinField, collectionName);
expect(filter).toEqual(expectedFilter);
});
});

View File

@ -142,6 +142,10 @@ export const transformToFilter = (
if (collectionField?.target) {
value = getValuesByPath(value, collectionField.targetKey || 'id');
key = `${key}.${collectionField.targetKey || 'id'}`;
if (collectionField?.interface === 'chinaRegion') {
value = _.last(value);
}
}
if (!value && value !== 0 && value !== false) {