File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
packages/core/server/content-api/services Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff 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 } ,
You can’t perform that action at this time.
0 commit comments