Strapi V4.11 sanitizeQuery, sanitizeInput and sanitizeOutput

System Information
  • Strapi Version: 4.11.1
  • Operating System: MacOS 12.5.1 monetery
  • Database: postgres
  • Node Version: node v18.15.0)
  • NPM Version: 9.5.0
  • Yarn Version: 1.22.19

I am trying to override a controller as below:


import {
  saveAProjectProduct, updateProductsQty, getOrganizationProduct, saveModelInputs,
  getProductDetails, getProjectModelInputs, getAllModelInputsForProject
} from "../services/impact-model-input"

import { factories } from '@strapi/strapi'

export default factories.createCoreController('api::impact-model-input.impact-model-input', ({ strapi }) => ({
  async getAllModelInputDataForProject (ctx: any ) {
    try {
      const projectId = <number>ctx.params['projectId']

      const sanitizedQueryParams = await this.sanitizeQuery(ctx);

      // find query params:
      const page = <number>ctx.request.query['page'] || 1
      const pageSize = <number>ctx.request.query['page-size'] || 500

      const results = await getAllModelInputsForProject(projectId, page, pageSize)

      ctx.response.status = 200
      ctx.body = results

    } catch (err) {
      console.error("error occurred: ", err)
      return ctx.internalServerError(err, { requestParams: ctx.request.body })
    }
  },

}));

When I compile/run this I am getting an error:

error TS2339: Property 'sanitizeQuery' does not exist on type '{ saveProjectProduct(ctx: any): Promise<any>; saveModelInputs(ctx: any): Promise<any>; updateProductQty(ctx: any): Promise<any>; getOneOrganizationProduct(ctx: any): Promise<...>; getProjectModelInputData(ctx: any): Promise<...>; getAllModelInputDataForProject(ctx: any): Promise<...>; }'.

123       const sanitizedQueryParams = await this.sanitizeQuery(ctx);

Looks like this is not what it seems to be available in docs and forums.

Please help me to understand where I am going wrong. According to the docs it’s clearly the right usage:

./src/api/restaurant/controllers/restaurant.ts

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

export default factories.createCoreController('api::restaurant.restaurant', ({ strapi }) =>  ({
  async findOne(ctx) {
    const sanitizedQueryParams = await this.sanitizeQuery(ctx);
    const { results, pagination } = await strapi.service('api::restaurant.restaurant').find(sanitizedQueryParams);
    const sanitizedResults = await this.sanitizeOutput(results, ctx);

    return this.transformResponse(sanitizedResults, { pagination });
  }
}));

Unfortunately none of these prescribed methods are available to me.

this.sanitizeOutput doesn’t exist on my end. How go I get that?

I got the same error.

Nobody every reply to this problem ? I’ve got exactly the same…