fix: query localized fields without localization configured

This commit is contained in:
Dan Ribbens
2023-04-21 21:12:30 -04:00
parent c251801b1a
commit 12edb1cc4b
4 changed files with 28 additions and 1 deletions

View File

@@ -449,7 +449,7 @@ export class ParamParser {
// Skip the next iteration, because it's a locale // Skip the next iteration, because it's a locale
i += 1; i += 1;
currentPath = `${currentPath}.${nextSegment}`; currentPath = `${currentPath}.${nextSegment}`;
} else if ('localized' in matchedField && matchedField.localized) { } else if (this.localizationConfig && 'localized' in matchedField && matchedField.localized) {
currentPath = `${currentPath}.${this.req.locale}`; currentPath = `${currentPath}.${this.req.locale}`;
} }

View File

@@ -75,6 +75,12 @@ export default buildConfig({
name: 'number', name: 'number',
type: 'number', type: 'number',
}, },
{
name: 'fakeLocalization',
type: 'text',
// field is localized even though the config localization is not on
localized: true,
},
// Relationship // Relationship
{ {
name: 'relationField', name: 'relationField',

View File

@@ -469,6 +469,24 @@ describe('collections-rest', () => {
}); });
}); });
describe('Edge cases', () => {
it('should query a localized field without localization configured', async () => {
const test = 'test';
await createPost({ fakeLocalization: test });
const { status, result } = await client.find({
query: {
fakeLocalization: {
equals: test,
},
},
});
expect(status).toEqual(200);
expect(result.docs).toHaveLength(1);
});
});
describe('Operators', () => { describe('Operators', () => {
it('equals', async () => { it('equals', async () => {
const valueToQuery = 'valueToQuery'; const valueToQuery = 'valueToQuery';

View File

@@ -23,6 +23,7 @@ export interface Post {
title?: string; title?: string;
description?: string; description?: string;
number?: number; number?: number;
fakeLocalization?: string;
relationField?: string | Relation; relationField?: string | Relation;
relationHasManyField?: string[] | Relation[]; relationHasManyField?: string[] | Relation[];
relationMultiRelationTo?: relationMultiRelationTo?:
@@ -55,6 +56,7 @@ export interface Post {
relationTo: 'dummy'; relationTo: 'dummy';
} }
)[]; )[];
restrictedField?: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
} }
@@ -66,6 +68,7 @@ export interface Relation {
} }
export interface Dummy { export interface Dummy {
id: string; id: string;
title?: string;
name?: string; name?: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;