Skip to content

Commit 7ed26fd

Browse files
committed
feat: fix eslint tslint
1 parent d450867 commit 7ed26fd

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

packages/core/server/controllers/search.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { Context } from 'koa';
2-
import { UID } from '@strapi/strapi';
2+
import { UID, Schema } from '@strapi/strapi';
33
import { errors } from '@strapi/utils';
44
import { isContentTypeEnabled } from '../util/enabledContentTypes';
55
import { 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-
117
interface 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');

packages/core/server/services/get-main-field.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ interface ContentManagerConfig {
66
};
77
}
88

9-
export const getMainField = async (uid: UID.CollectionType): Promise<string | null> => {
10-
const coreStoreSettings = await strapi.query('strapi::core-store').findMany({
11-
where: { key: `plugin_content_manager_configuration_content_types::${uid}` },
12-
}) as Array<{ value: string }>;
9+
export const getMainField = async (uid: UID.ContentType): Promise<string | null> => {
10+
const coreStoreSettings = (await strapi
11+
.query('strapi::core-store' as unknown as UID.Schema)
12+
.findMany({
13+
where: { key: `plugin_content_manager_configuration_content_types::${uid}` },
14+
})) as Array<{ value: string }>;
1315

1416
if (!coreStoreSettings?.[0]) return null;
1517

0 commit comments

Comments
 (0)