Skip to content

Commit 18b135b

Browse files
authored
Merge pull request #199 from pluginpal/feature/fix-single-type=issue
fix: issue in the router endpoint while querying a single type that d…
2 parents 9152602 + 9e21d15 commit 18b135b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.changeset/eleven-glasses-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pluginpal/webtools-core": patch
3+
---
4+
5+
Issue in the router endpoint when querying a single type which does not have localizations enabled.

packages/core/server/content-api/services/by-path.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default () => ({
2828
excludeDrafts = true;
2929
}
3030

31-
const entity = await strapi.entityService.findMany(contentTypeUid, {
31+
const entities = await strapi.entityService.findMany(contentTypeUid, {
3232
...query,
3333
filters: {
3434
...query?.filters,
@@ -42,12 +42,20 @@ export default () => ({
4242
limit: 1,
4343
});
4444

45-
if (!entity[0]) {
45+
/**
46+
* If we're querying a single type, which does not have localizations enabled,
47+
* Strapi will return a single entity instead of an array. Which is slightly weird,
48+
* because the API we're querying is called `findMany`. That's why we need to check
49+
* if the result is an array or not and handle it accordingly.
50+
*/
51+
const entity = Array.isArray(entities) ? entities[0] : entities;
52+
53+
if (!entity) {
4654
return {};
4755
}
4856

4957
return {
50-
entity: entity[0],
58+
entity,
5159
contentType: urlAliasEntity.contenttype as Common.UID.ContentType,
5260
};
5361
},

0 commit comments

Comments
 (0)