Skip to content

Commit dae1ea1

Browse files
committed
Update get entry methods name
1 parent 6107e03 commit dae1ea1

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

server/__tests__/content-types.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('Tests content types', () => {
103103
strapi: fakeStrapi,
104104
})
105105

106-
const count = await contentTypeServices.getContentTypeEntries({
106+
const count = await contentTypeServices.getEntries({
107107
contentType: 'api::restaurant.restaurant',
108108
})
109109

@@ -115,7 +115,7 @@ describe('Tests content types', () => {
115115
strapi: fakeStrapi,
116116
})
117117

118-
const count = await contentTypeServices.getContentTypeEntries({
118+
const count = await contentTypeServices.getEntries({
119119
contentType: 'api::test.test',
120120
})
121121

server/services/content-types/content-types.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,38 @@ module.exports = ({ strapi }) => ({
120120
return entriesSum
121121
},
122122

123+
/**
124+
* Find an entry of a given content type.
125+
* More information: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/crud.html#findone
126+
*
127+
* @param {object} options
128+
* @param {string} [options.id] - Id of the entry.
129+
* @param {string | string[]} [options.fields] - Fields present in the returned entry.
130+
* @param {object} [options.populate] - Relations, components and dynamic zones to populate.
131+
* @param {string} [options.contentType] - Content type.
132+
*
133+
* @returns {Promise<object>} - Entries.
134+
*/
135+
async getEntry({ contentType, id, fields = '*', populate = '*' }) {
136+
const contentTypeUid = this.getContentTypeUid({ contentType })
137+
if (contentTypeUid === undefined) return {}
138+
139+
const entry = await strapi.entityService.findOne(contentTypeUid, id, {
140+
fields,
141+
populate,
142+
})
143+
144+
if (entry == null) {
145+
strapi.log.error(`Could not find entry with id ${id} in ${contentType}`)
146+
}
147+
148+
return entry
149+
},
150+
123151
/**
124152
* Returns a batch of entries of a given content type.
125153
* More information: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/crud.html#findmany
154+
*
126155
* @param {object} options
127156
* @param {string | string[]} [options.fields] - Fields present in the returned entry.
128157
* @param {number} [options.start] - Pagination start.
@@ -135,7 +164,7 @@ module.exports = ({ strapi }) => ({
135164
*
136165
* @returns {Promise<object[]>} - Entries.
137166
*/
138-
async getContentTypeEntries({
167+
async getEntries({
139168
contentType,
140169
fields = '*',
141170
start = 0,
@@ -182,7 +211,7 @@ module.exports = ({ strapi }) => ({
182211
const cbResponse = []
183212
for (let index = 0; index <= entries_count; index += BATCH_SIZE) {
184213
const entries =
185-
(await this.getContentTypeEntries({
214+
(await this.getEntries({
186215
start: index,
187216
limit: BATCH_SIZE,
188217
contentType,

server/services/meilisearch/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = ({ strapi }) => {
4242
* @param {Array<Object>} options.entries - The data to convert. Conversion will use
4343
* the static method `toSearchIndex` defined in the model definition
4444
*
45-
* @return {Array<Object>} - Converted or mapped data
45+
* @return {Promise<Array<Object>>} - Converted or mapped data
4646
*/
4747
transformEntries: async function ({ contentType, entries = [] }) {
4848
const collection = contentTypeService.getCollectionName({ contentType })

0 commit comments

Comments
 (0)