Naming schema in strapi.services/strapi.models

Hello,

I want to change my findOne-controller to get the data via slug and not via id.

This works well for my article-model.

But with the same code I got problems for my article categories. I always get an 500 internal server error

My code from /app/api/article-category/controllers/article-category.js:

const { sanitizeEntity } = require('strapi-utils');

module.exports = {

  async findOne (ctx) {
    const { slug } = ctx.params;

    const entity = await strapi.services.article-category.findOne({ slug });
    return sanitizeEntity(entity, { model: strapi.models.article-category });
  },
};

I don’t know what the right naming to get the services and model for my article-category.

Thanks for some help with this!

Best regards,

Timo

I found the solution for my problem.

It was a notation error to get the right data:

const { sanitizeEntity } = require('strapi-utils');

module.exports = {

  async findOne (ctx) {
    const { slug } = ctx.params;

    const entity = await strapi.services['article-category'].findOne({ slug });
    return sanitizeEntity(entity, { model: strapi.models['article-category'] });
  },
};
1 Like