Help with project Structure


#1

Hello everyone,

I have a doubt related to project structure.
In this example, it is clear I have a method in my async controller that runs through all my model objects.

  async charge({ response }) {
    const projects = await Project.where('suspended', false).fetch();
    const promisses = [];

    projects.forEach((project) => {
      promisses.push(
        this.chargeProject(project),
      );
    });

    await Promise.all(promisses);

    return response.apiCollection(true);
  }

  async chargeProject(project) {
    process.users_count = 0;
    if (!project.isValidateToCharge()) {
      return false;
    }

    const invoice = new Invoice();
    invoice.createInvoice(project, Plans.all());
    invoice.save();
    await project.chage(invoce);
    project.save();

    return true;
    

  }

Following the idea that the model does not communicate with another model, I need to solve with a promise all. I had to create a new method inside the own controller to solve all interactions with my object.

But I believe if you continue with this model my controller will grow a lot with “private” methods which I do not believe is a good way.

What is the best way to keep this part more related to business?