fix: rest api with ?locale=* doesn't return full localized data (#10619)
Fixes https://github.com/payloadcms/payload/issues/9712
This commit is contained in:
@@ -69,7 +69,7 @@ export const sanitizeLocales = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locale === '*') {
|
if (['*', 'all'].includes(locale)) {
|
||||||
locale = 'all'
|
locale = 'all'
|
||||||
} else if (localization && !localization.localeCodes.includes(locale) && localization.fallback) {
|
} else if (localization && !localization.localeCodes.includes(locale) && localization.fallback) {
|
||||||
locale = localization.defaultLocale
|
locale = localization.defaultLocale
|
||||||
|
|||||||
@@ -78,11 +78,6 @@ export const createPayloadRequest = async ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
locale = locales.locale
|
locale = locales.locale
|
||||||
|
|
||||||
// Override if query params are present, in order to respect HTTP method override
|
|
||||||
if (query.locale) {
|
|
||||||
locale = query.locale as string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const customRequest: CustomPayloadRequestProperties = {
|
const customRequest: CustomPayloadRequestProperties = {
|
||||||
|
|||||||
@@ -276,6 +276,34 @@ describe('Localization', () => {
|
|||||||
expect(localized.title.es).toEqual(spanishTitle)
|
expect(localized.title.es).toEqual(spanishTitle)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('REST all locales with all', async () => {
|
||||||
|
const response = await restClient.GET(`/${collection}/${localizedPost.id}`, {
|
||||||
|
query: {
|
||||||
|
locale: 'all',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
const localized = await response.json()
|
||||||
|
|
||||||
|
expect(localized.title.en).toEqual(englishTitle)
|
||||||
|
expect(localized.title.es).toEqual(spanishTitle)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('REST all locales with asterisk', async () => {
|
||||||
|
const response = await restClient.GET(`/${collection}/${localizedPost.id}`, {
|
||||||
|
query: {
|
||||||
|
locale: '*',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
const localized = await response.json()
|
||||||
|
|
||||||
|
expect(localized.title.en).toEqual(englishTitle)
|
||||||
|
expect(localized.title.es).toEqual(spanishTitle)
|
||||||
|
})
|
||||||
|
|
||||||
it('by localized field value - default locale', async () => {
|
it('by localized field value - default locale', async () => {
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
collection,
|
collection,
|
||||||
|
|||||||
Reference in New Issue
Block a user