Service file is big, how do i split it into multiple files?

Some of my controller and services have some pretty intense business logic.

I want to break my services and controllers up into multiple files but have the main file import the methods from these other files to build up one service or controller.

An example is my ‘order’ collection, im looking for something like this → any comments and thoughts?

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

import refundMethods from "./order-refund.ts"
import notificationMethods from "./order-notification.ts"

export default factories.createCoreService('api::order.order', ({ strapi }) => ({
  // the usual
  async create() {
    // custom logic and whatever
    return super()
  // new custom methods

This topic has been created from a Discord post (1249756215618306170) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

yeah you can certainly split them off if you want and import them as needed

This does not run though.

I was asking to get some feedback on what would be the best way to do this?

I cant just have a file that exports a method in a controller folder because strapi tries to read that file and its not in the convention that it wants it.

In your opinion what is my best bet to still have access to this and super ? I dont want to wrap every file of custom methods in createCoreController or createCoreService because thats going to create a bloat of create etc methods.

I made a typing like this, not preferrable but works:

type This = Partial<CoreApi.Controller.CollectionType> & CoreApi.Controller.Generic;

export default {
  async customMethod(this: This, ctx) {
    const sanitizedQueryInput: any = await this.sanitizeInput(ctx.request.body, ctx);
    const sanitizedQueryParams: any = await this.sanitizeQuery(ctx);

I made a typing like this, not preferrable but it works:

For that I’m not really sure to be honest with you, it’s the nature of the way those functions work