All files / libs/payout-calculation/statements/core/src statements.tasks.ts

0% Statements 0/83
0% Branches 0/1
0% Functions 0/1
0% Lines 0/83

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                                                                                                                                                                       
import { type INestApplicationContext } from '@nestjs/common';

import {
  MessageTasks,
  type DeliverWorkflowCampaignStartedNotificationPayload,
  type ProcessWorkflowStepBulkPayload,
  type QueueMessageAttributes,
  type QueueMessageContent,
} from '@amalia/kernel/queue/core';

import { ChallengesModule } from './modules/gamification/challenges/challenges.module';
import { ChallengesService } from './modules/gamification/challenges/challenges.service';
import { StatementReviewModule } from './modules/review/statement-review.module';
import { StatementsReviewService } from './modules/review/statements-review.service';
import { AutoStartWorkflowCampaignsAndNotifyFirstStepReviewersUseCase } from './modules/review/use-cases/auto-start-worklow-campaigns-and-notify-first-step-reviewers/auto-start-workflow-campaigns-and-notify-first-step-reviewers.use-case';
import { NotifyFirstStepReviewersStatementStandaloneReviewUseCase } from './modules/review/use-cases/notify-first-step-reviewers-statement-standalone-review.use-case.ts/notify-first-step-reviewers-statement-standalone-review.use-case';
import { NotifyFirstStepReviewersWorkflowCampaignStartedUseCase } from './modules/review/use-cases/notify-first-step-reviewers-workflow-campaign-started/notify-first-step-reviewers-workflow-campaign-started.use-case';
import { NotifyPendingReviewsUseCase } from './modules/review/use-cases/notify-pending-reviews/notify-pending-reviews.use-case';
import { StatementsModule } from './modules/statements/statements.module';

export const executeStatementsTask = async (
  app: INestApplicationContext,
  attributes: QueueMessageAttributes<MessageTasks>,
  messageContent: QueueMessageContent,
) => {
  switch (attributes.taskIdentifier) {
    case MessageTasks.PROCESS_WORKFLOW_STEP_BULK: {
      const { companyId, statementIds, isNotify, action, currentUserId } =
        messageContent as ProcessWorkflowStepBulkPayload;
      await app
        .select(StatementsModule)
        .get(StatementsReviewService)
        .handleProcessWorkflowStepInBulk(companyId, statementIds, currentUserId, action, isNotify);
      break;
    }

    case MessageTasks.DELIVER_SLACK_CHALLENGES: {
      await app
        .select(ChallengesModule)
        .get(ChallengesService)
        .deliverChallengesSlackNotifications((messageContent as { companyIds: string[] }).companyIds);
      break;
    }

    case MessageTasks.SEND_STATEMENT_REVIEW_WEEKLY_REMINDER: {
      await app.select(StatementReviewModule).get(NotifyPendingReviewsUseCase).execute();
      break;
    }

    case MessageTasks.DELIVER_WORKFLOW_CAMPAIGN_STARTED_NOTIFICATION: {
      const { companyId, periodId, planIds } = messageContent as DeliverWorkflowCampaignStartedNotificationPayload;
      await app
        .select(StatementReviewModule)
        .get(NotifyFirstStepReviewersWorkflowCampaignStartedUseCase)
        .execute({ companyId, periodId, planIds });
      break;
    }

    case MessageTasks.AUTO_START_WORKFLOW_CAMPAIGNS_AND_NOTIFY_FIRST_STEP_REVIEWERS: {
      await app
        .select(StatementReviewModule)
        .get(AutoStartWorkflowCampaignsAndNotifyFirstStepReviewersUseCase)
        .execute();
      break;
    }

    case MessageTasks.DELIVER_NOTIFICATION_STANDALONE_REVIEW_ENABLED_FOR_STATEMENT: {
      const { statementId, companyId } = messageContent as { statementId: string; companyId: string };
      await app.select(StatementReviewModule).get(NotifyFirstStepReviewersStatementStandaloneReviewUseCase).execute({
        statementId,
        companyId,
      });
      break;
    }

    default:
      // Will not handle any task.
      return false;
  }

  // Task have been handled.
  return true;
};