Why isn't this snippet from v3 working in v4?

System Information
  • Strapi Version: 4.0.2
  • Operating System: MacOS
  • Node Version: >= 12.x.x <= 16.x.x
  • NPM Version: 6.0.0
  • Yarn Version:

Hello, I’m new here so sorry if this is in the wrong place. I have been following along on this tutorial (how to create a blog with SvelteKit and strapi) but using v4 instead of v3. So far I have been able to translate everything to v4, but I cannot figure out what I need to change here:

    "use strict";
    
    const { parseMultipartData, sanitizeEntity } = require("strapi-utils");
    
    /**
     * Read the documentation (https://docs.strapi.io/developer-docs/latest/development/backend-customization.html#core-controllers)
     * to customize this controller
     */
    
    module.exports = {
      async create(ctx) {
        let entity;
    
        if (ctx.is("multipart")) {
          const { data, files } = parseMultipartData(ctx);
          data.author = ctx.state.user.id;
          entity = await strapi.services.post.create(data, { files });
        } else {
          ctx.request.body.author = ctx.state.user.id;
          entity = await strapi.services.post.create(ctx.request.body);
        }
    
        return sanitizeEntity(entity, { model: strapi.models.post });
      },
    
      async update(ctx) {
        const { id } = ctx.params;
    
        let entity;
    
        const [article] = await strapi.services.post.find({
          id: ctx.params.id,
          "author.id": ctx.state.user.id,
        });
    
        if (!article) {
          return ctx.unauthorized(`You can't update this entry`);
        }
    
        if (ctx.is("multipart")) {
          const { data, files } = parseMultipartData(ctx);
          entity = await strapi.services.post.update({ id }, data, {
            files,
          });
        } else {
          entity = await strapi.services.post.update({ id }, ctx.request.body);
        }
    
        return sanitizeEntity(entity, { model: strapi.models.post });
      },

I have installed @strapi/utils already and the current error I am getting is: Error creating endpoint GET /posts: Handler not found “api::post.post.find”

I would appreciate any help I can get. Thanks!

I had the same problem too. This works for me:

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::post.post', ({ strapi }) =>  ({
    async create(ctx) {
        ... your code ...
    }
    async update(ctx) {
        ... your code ...
    }
}))