11import { Context } from 'koa' ;
2- import { UID } from '@strapi/strapi' ;
2+ import { UID , Schema } from '@strapi/strapi' ;
33import { errors } from '@strapi/utils' ;
44import { isContentTypeEnabled } from '../util/enabledContentTypes' ;
55import { getPluginService } from '../util/getPluginService' ;
66
7- interface ContentTypeConfig {
8- [ key : string ] : any ; // We only pass this to isContentTypeEnabled, so any is fine here
9- }
10-
117interface DocumentEntry {
128 id : number ;
139 documentId : string ;
@@ -33,22 +29,21 @@ export default {
3329
3430 await Promise . all (
3531 Object . entries ( strapi . contentTypes ) . map (
36- async ( [ uid , config ] : [ UID . CollectionType , ContentTypeConfig ] ) => {
32+ async ( [ uid , config ] : [ UID . ContentType , Schema . ContentType ] ) => {
3733 const hasWT = isContentTypeEnabled ( config ) ;
3834 if ( ! hasWT ) return ;
3935
4036 const mainField = await getPluginService ( 'get-main-field' ) . getMainField ( uid ) ;
4137 if ( ! mainField ) return ;
4238
43- const entries : DocumentEntry [ ] = await strapi . documents ( uid ) . findMany ( {
39+ const fieldsArr : string [ ] = [ 'documentId' , ...( mainField ? [ mainField ] : [ ] ) ] ;
40+
41+ const entries = ( await strapi . documents ( uid ) . findMany ( {
4442 filters : {
4543 [ mainField ] : { $containsi : qStr } ,
4644 } ,
47- fields : [ mainField , 'documentId' ] ,
48- populate : {
49- url_alias : { fields : [ 'id' ] } ,
50- } ,
51- } ) ;
45+ fields : fieldsArr ,
46+ } as any ) ) as unknown as DocumentEntry [ ] ;
5247
5348 if ( ! entries || entries . length === 0 ) return ;
5449
@@ -72,13 +67,17 @@ export default {
7267 }
7368
7469 const mainField = await getPluginService ( 'get-main-field' ) . getMainField (
75- contentType as UID . CollectionType ,
70+ contentType as UID . ContentType ,
7671 ) ;
7772 // eslint-disable-next-line max-len
78- const entry : DocumentEntry | null = await strapi . documents ( contentType as UID . CollectionType ) . findOne ( {
79- documentId,
80- fields : [ 'id' , 'documentId' , ...( mainField ? [ mainField ] : [ ] ) ] ,
81- } ) ;
73+ const fieldsArr : string [ ] = [ 'id' , 'documentId' , ...( mainField ? [ mainField ] : [ ] ) ] ;
74+
75+ const entry = ( await strapi
76+ . documents ( contentType as UID . ContentType )
77+ . findOne ( {
78+ documentId,
79+ fields : fieldsArr ,
80+ } as any ) ) as unknown as DocumentEntry | null ;
8281
8382 if ( ! entry ) {
8483 throw new errors . NotFoundError ( 'Entry not found' ) ;
0 commit comments