Override core controller not working for create, update, delete but works for find

I am trying to override the core controller to auto update a field when a new entry is created in my announcements page. But when when Itry to override the methods for create update or delete it doesnt work while the same works for the find method. Can anyone help identify what the issue is?

'use strict';

/**
 * announcement controller
 */

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

module.exports = createCoreController('api::announcement.announcement', ({strapi}) => ({
    async find(ctx){
        const { data, meta } = await super.find(ctx);
        console.log("-----------------------------------------");
        console.log(data);
        return { data, meta }
    },
    async create(ctx) {
        console.log('-------------------CREATE------------------------------');
        const response = await super.create(ctx);
        console.log("-----------RESPONSE-------------");
        console.log(response);
        return response;
    },
    async update(ctx) {
        console.log("---------------------UPDATE----------------------------");
        const response = await super.update(ctx);
        console.log("----------------------");
        console.log(response);
        return response;
      },
    async delete(ctx) {
        // some logic here
        console.log("---------------------DELETEE----------------------------");
        const response = await super.delete(ctx);
        // some more logic
      
        return response;
      },
}));
type or paste code here

You can owerride request.body.data as you need.

The next code adds User from the default plugin User & Permissions to the Todo entity

/**
 * todo controller
 */

import { factories } from "@strapi/strapi";

export default factories.createCoreController(
  "api::todo.todo",
  ({ strapi }) => ({
    async create(ctx) {
      ctx.request.body.data.user = ctx.state.user;
      await super.create(ctx);
    },
  })
);

OK. There is another way. You can customize life cycles

As I understand it this way is preferable.

Declarative sample

./src/api/todo/content-types/todo/lifecycles.ts is the declare file path

export default {
  async beforeCreate(event) {
    const ctx = await strapi.requestContext.get();
    event.params.data.user = ctx.state.user; //  Add User from the default plugin User & Permissions to the Todo entity
    event.params.data.state = { id: 1 }; // Add default State to the Todo entity
  },
};

Thanks for the great comunity Strapi — русскоговорящее сообщество