title: NestJs best practice for service endpoints
body: <p>I am designing a Cron service that calls different endpoints at specified times of the day. Here is a sample method i have in my cron service.</p>
  <pre><code>
    @Cron(CronExpression.EVERY_DAY_AT_6AM)
    async pollScheduledRecords() {
      const jwtToken = await this.authService.retrieveJwtToken();
      const recordsForToday =
        await this.scheduleService.getScheduleRecordsForToday();
      return recordsForToday.map((individualRecord) =&gt; {
        this.scheduleService.updateScheduleRecordStatus({
          id: individualRecord.id,
          updatedStatus: JobStatus.ONGOING,
        });
        return this.pcfPricingService
          .triggerDataLoader({
            experimentId: individualRecord.experimentId,
            variantId: individualRecord.variantId,
            token: `Bearer ${jwtToken}`,
            scheduleRecordId: individualRecord.id,
          })
          .subscribe();
      });
    }
  </code></pre>
  <p>Let me explain what i am doing here.</p>
  <ol>
  <li>Retrieving a jwt token from my authservice</li>
  <li>getting all records scheduled to run today from my schedule service</li>
  <li>Since the records are in an array, I map them and on each record I:</li>
  </ol>
  <ul>
  <li>Update each records status to ongoing</li>
  <li>Execute the job type - this case being dataloader.</li>
  </ul>
  <p>My question is:
  How can i refactor this to make it cleaner? I am finding it very hard to write a unit test for it.</p>
  <p>Thank you. Appreciate the feedback.</p>