Repository: novuhq/novu
File: apps/worker/src/app/workflow/usecases/subscriber-job-bound/subscriber-job-bound.usecase.ts (TypeScript)

Code before:
       * TODO: refactor the Worker execution to handle both stateless and stateful workflows
       * transparently.
       */
      ...(command.bridge?.workflow && {
        preferences: buildWorkflowPreferences(command.bridge?.workflow?.preferences),
      }),
    };

    if (actor) {
      createNotificationJobsCommand.actor = actor;
    }

    const notificationJobs = await this.createNotificationJobs.execute(
      CreateNotificationJobsCommand.create(createNotificationJobsCommand)
    );

    await this.storeSubscriberJobs.execute(
      StoreSubscriberJobsCommand.create({
        environmentId: command.environmentId,
        jobs: notificationJobs,
        organizationId: command.organizationId,
      })
    );
  }

  private async mapBridgeWorkflow(command: SubscriberJobBoundCommand): Promise<NotificationTemplateEntity | null> {
    const bridgeWorkflow = command.bridge?.workflow;

    if (!bridgeWorkflow) {
      return null;
    }

    const storedWorkflowId = (
      await this.notificationTemplateRepository.findByTriggerIdentifier(
        command.environmentId,
        bridgeWorkflow.workflowId
      )
    )?._id;

    /*
     * Cast used to convert data type for further processing.
     * todo Needs review for potential data corruption.
     */
    return {
      ...bridgeWorkflow,
      type: WorkflowTypeEnum.BRIDGE,
      _id: storedWorkflowId,
      steps: bridgeWorkflow.steps.map((step) => {
        const stepControlVariables = command.controls?.steps?.[step.stepId];

        return {

Review comment (suggestion):
```suggestion
  private async getNotificationTemplateFromBridge(command: SubscriberJobBoundCommand): Promise<NotificationTemplateEntity | null> {
```

Code after:
       * TODO: refactor the Worker execution to handle both stateless and stateful workflows
       * transparently.
       */
      ...(command.bridge?.workflow && {
        preferences: buildWorkflowPreferences(command.bridge?.workflow?.preferences),
      }),
    };

    if (actor) {
      createNotificationJobsCommand.actor = actor;
    }

    const notificationJobs = await this.createNotificationJobs.execute(
      CreateNotificationJobsCommand.create(createNotificationJobsCommand)
    );

    await this.storeSubscriberJobs.execute(
      StoreSubscriberJobsCommand.create({
        environmentId: command.environmentId,
        jobs: notificationJobs,
        organizationId: command.organizationId,
      })
    );
  }

  private async getCodeFirstWorkflow(command: SubscriberJobBoundCommand): Promise<NotificationTemplateEntity | null> {
    const bridgeWorkflow = command.bridge?.workflow;

    if (!bridgeWorkflow) {
      return null;
    }

    const syncedWorkflowId = (
      await this.notificationTemplateRepository.findByTriggerIdentifier(
        command.environmentId,
        bridgeWorkflow.workflowId
      )
    )?._id;

    /*
     * Cast used to convert data type for further processing.
     * todo Needs review for potential data corruption.
     */
    return {
      ...bridgeWorkflow,
      type: WorkflowTypeEnum.BRIDGE,
      _id: syncedWorkflowId,
      steps: bridgeWorkflow.steps.map((step) => {
        const stepControlVariables = command.controls?.steps?.[step.stepId];

        return {