From de66e3b08806d932247637260360c9ca72847ae8 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Tue, 10 Jun 2025 16:54:39 +0200 Subject: [PATCH 1/2] Add GroupNameEnum and update TargetUnit types (#57) - Introduced `GroupNameEnum` in `weeklyFinancialReport.ts` to define group names for financial reports. - Updated `types.ts` to import `GroupNameEnum` and added a new type `GroupName` based on the enum. These changes enhance type safety and improve the organization of group name constants within the application. --- workers/main/src/common/types.ts | 4 ++++ workers/main/src/configs/weeklyFinancialReport.ts | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 workers/main/src/configs/weeklyFinancialReport.ts diff --git a/workers/main/src/common/types.ts b/workers/main/src/common/types.ts index 2978f2b..32f007c 100644 --- a/workers/main/src/common/types.ts +++ b/workers/main/src/common/types.ts @@ -1,3 +1,5 @@ +import { GroupNameEnum } from '../configs'; + export interface TargetUnit { group_id: number; group_name: string; @@ -10,3 +12,5 @@ export interface TargetUnit { rate?: number; projectRate?: number; } + +export type GroupName = (typeof GroupNameEnum)[keyof typeof GroupNameEnum]; diff --git a/workers/main/src/configs/weeklyFinancialReport.ts b/workers/main/src/configs/weeklyFinancialReport.ts new file mode 100644 index 0000000..e40c0da --- /dev/null +++ b/workers/main/src/configs/weeklyFinancialReport.ts @@ -0,0 +1,4 @@ +export enum GroupNameEnum { + SD_REPORT = 'SD Weekly Financial Report', + ED_REPORT = 'ED Weekly Financial Report', +} From b3081df06f5965fb7d93b26d75ad3f4a2efc0023 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Tue, 10 Jun 2025 17:11:23 +0200 Subject: [PATCH 2/2] Enhance weekly financial reports workflow with group name validation - Updated `weeklyFinancialReportsWorkflow` to accept a `groupName` parameter, ensuring it is validated against the `GroupNameEnum`. - Added error handling to throw an `AppError` for invalid group names, improving robustness and clarity in error reporting. - Modified the corresponding test to reflect the new parameter usage. These changes enhance the workflow's functionality and ensure that only valid group names are processed. --- .../weeklyFinancialReports.workflow.test.ts | 5 ++++- .../weeklyFinancialReports.workflow.ts | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts b/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts index 1353375..3334116 100644 --- a/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts +++ b/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it, vi } from 'vitest'; +import { GroupNameEnum } from '../../configs/weeklyFinancialReport'; import { weeklyFinancialReportsWorkflow } from './weeklyFinancialReports.workflow'; vi.mock('@temporalio/workflow', () => ({ @@ -12,7 +13,9 @@ vi.mock('@temporalio/workflow', () => ({ describe('weeklyFinancialReportsWorkflow', () => { it('returns the fileLink from getTargetUnits', async () => { - const result = await weeklyFinancialReportsWorkflow(); + const result = await weeklyFinancialReportsWorkflow( + GroupNameEnum.ED_REPORT, + ); expect(result).toBe('sub-dir/mocked-link.json'); }); diff --git a/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts b/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts index 25a6322..2c1a6fa 100644 --- a/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts +++ b/workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts @@ -1,12 +1,23 @@ import { proxyActivities } from '@temporalio/workflow'; import type * as activities from '../../activities/weeklyFinancialReports'; +import { AppError } from '../../common/errors'; +import { GroupName } from '../../common/types'; +import { GroupNameEnum } from '../../configs/weeklyFinancialReport'; const { getTargetUnits } = proxyActivities({ startToCloseTimeout: '10 minutes', }); -export async function weeklyFinancialReportsWorkflow(): Promise { +export async function weeklyFinancialReportsWorkflow( + groupName: GroupName, +): Promise { + if (!(Object.values(GroupNameEnum) as GroupName[]).includes(groupName)) { + throw new AppError( + `Invalid groupName paramter: ${groupName}. Allowed values: "${Object.values(GroupNameEnum).join('", "')}"`, + 'weeklyFinancialReportsWorkflow', + ); + } const targetUnits = await getTargetUnits(); return targetUnits.fileLink;