Skip to content

Commit 475cc3a

Browse files
bors[bot]bidoubiwa
andauthored
Merge #123
123: Fix plugin failing when single types existed r=bidoubiwa a=bidoubiwa Before we decide how to handle `single types` in MeiliSearch this PR fixes the issue by removing single types from the types selection in the plugin. Fixes #122 open issue: #124 Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents 3302247 + 0d84570 commit 475cc3a

File tree

8 files changed

+96
-2
lines changed

8 files changed

+96
-2
lines changed

controllers/meilisearch.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,18 @@ async function fetchRowBatch({ start, limit, collection }) {
119119
})
120120
}
121121

122+
function getCollectionTypes() {
123+
const services = strapi.services
124+
return Object.keys(services).filter(type => {
125+
return services[type].count
126+
})
127+
}
128+
122129
async function numberOfRowsInCollection({ collection }) {
123-
return strapi.services[collection].count({ _publicationState: 'preview' })
130+
return (
131+
strapi.services[collection].count &&
132+
strapi.services[collection].count({ _publicationState: 'preview' })
133+
)
124134
}
125135

126136
async function batchAddCollection(ctx) {
@@ -170,7 +180,9 @@ async function getStats({ collection }) {
170180
async function getCollections() {
171181
const indexes = await getIndexes()
172182
const hookedCollections = await getHookedCollections()
173-
const collections = Object.keys(strapi.services).map(async collection => {
183+
const collectionTypes = getCollectionTypes()
184+
185+
const collections = collectionTypes.map(async collection => {
174186
const existInMeilisearch = !!indexes.find(
175187
index => index.name === collection
176188
)

playground/.tmp/data.db

0 Bytes
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"routes": [
3+
{
4+
"method": "GET",
5+
"path": "/single-type-test",
6+
"handler": "single-type-test.find",
7+
"config": {
8+
"policies": []
9+
}
10+
},
11+
{
12+
"method": "PUT",
13+
"path": "/single-type-test",
14+
"handler": "single-type-test.update",
15+
"config": {
16+
"policies": []
17+
}
18+
},
19+
{
20+
"method": "DELETE",
21+
"path": "/single-type-test",
22+
"handler": "single-type-test.delete",
23+
"config": {
24+
"policies": []
25+
}
26+
}
27+
]
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
/**
4+
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
5+
* to customize this controller
6+
*/
7+
8+
module.exports = {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
/**
4+
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks)
5+
* to customize this model
6+
*/
7+
8+
module.exports = {};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"kind": "singleType",
3+
"collectionName": "single_type_tests",
4+
"info": {
5+
"name": "Single Type Test"
6+
},
7+
"options": {
8+
"increments": true,
9+
"timestamps": true,
10+
"draftAndPublish": true
11+
},
12+
"attributes": {
13+
"title": {
14+
"type": "string"
15+
}
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
/**
4+
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services)
5+
* to customize this service
6+
*/
7+
8+
module.exports = {};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"collectionName": "components_test_component_tests",
3+
"info": {
4+
"name": "Component-test",
5+
"icon": "bong"
6+
},
7+
"options": {},
8+
"attributes": {
9+
"title": {
10+
"type": "string"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)