I'm trying developer an ecommerce API and I have a question:
What's the difference between the super.find() and a strapi.entityService?
I have a product controller and I changed the find controller:
products/controller/products.js
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::product.product", ({ strapi }) => ({
async find(ctx){
const data = await super.find(ctx);
...
//const data = await strapi.entityService.findMany("api::product.product");
return data
}
Inside the function has a super.find and then has returning a specific structure of JSON, like this:
{
"data": [
{
"id": 8,
"attributes": {
"name": "Fiat Marea 20V ",
"sku": "FT550",
"description": "<p>Apenas uma descrição de teste Produto único topzeira </p><p> </p><p><strong>Altura</strong>: 12 </p><p><strong>Largura</strong>: 12 </p><p><strong>Produnfidade</strong>: 12</p>",
"price": 19900,
"status": true,
"createdAt": "2022-12-02T22:23:47.483Z",
"updatedAt": "2023-01-05T12:31:08.461Z",
"quantity": 2,
"price_discount": null,
"publishedAt": "2023-01-05T12:14:25.342Z"
}
}
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 25,
"pageCount": 1,
"total": 1
}
}
}
The structure of products startes with you id and your attributes but... If I use the await strapi.entityService.findMany("api::product.product") I has this return:
[
{
"id": 8,
"name": "Fiat Marea 20V ",
"sku": "FT550",
"description": "<p>Apenas uma descrição de teste Produto único topzeira </p><p> </p><p><strong>Altura</strong>: 12 </p><p><strong>Largura</strong>: 12 </p><p><strong>Produnfidade</strong>: 12</p>",
"price": 19900,
"status": true,
"createdAt": "2022-12-02T22:23:47.483Z",
"updatedAt": "2023-01-05T12:31:08.461Z",
"quantity": 2,
"price_discount": null,
"publishedAt": "2023-01-05T12:14:25.342Z"
}
]
The structures of return is different, but why? how I can receive the same structure of super.find() using the strapi.entityService or strapi.query?
How can I solve this problem?