I am trying to wrap a basic strapi.entityService.findMany("api::product-update.product-update")
in a separate function in a separate file. At some point I will add searchCriteria as params and it will get too verbose if I reuse. the function in a controller.
Here is the function I am using:
getEntities.ts
import { TObject } from "../types/global";
export type ContentType = Registry.Keys<Shared.ContentTypes, UID.ContentType>;
export const getEntities = async <T>(
model: string,
criteria: TObject
): Promise<T[]> => {
const entities = await strapi.entityService.findMany(
`api::${model}.${model}` as ContentType,
{
...criteria,
}
);
return entities as T[];
};
The problem with the getEntities
is that when using it, I get zero autocomplete to show variables in the result, that’s not the case when I use strapi.entityService.findMany
directly.
I tried using a basic function at first:
model: string,
criteria: TObject
) => {
const entities = await strapi.entityService.findMany(
`api::${model}.${model}`,
{
...criteria,
}
);
return entities;
};```
However the ``api::${model}.${model}`` params is throwing an error , which is why I tried the method mentionned above.```Argument of type '`api::${string}.${string}`' is not assignable to parameter of type 'ContentType'.```
<i>This topic has been created from a Discord post (1251188597814722571) to give it more visibility.
It will be on Read-Only mode here.
<a href="https://discord.com/channels/811989166782021633/1251188597814722571/1251188597814722571">Join the conversation on Discord</a></i>