Skip to content

Commit

Permalink
feat(dashboard): minor fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ChmaraX committed Dec 9, 2024
1 parent 546801d commit 0302cd8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { buildSlug } from '../../shared/helpers/build-slug';

export function toResponseWorkflowDto(
workflow: WorkflowInternalResponseDto,
fullSteps: StepDataDto[]
steps: StepDataDto[]
): WorkflowResponseDto {
const preferencesDto: PreferencesResponseDto = {
user: workflow.userPreferences,
Expand All @@ -33,7 +33,7 @@ export function toResponseWorkflowDto(
tags: workflow.tags,
active: workflow.active,
preferences: preferencesDto,
steps: fullSteps,
steps: steps,
description: workflow.description,
origin: computeOrigin(workflow),
updatedAt: workflow.updatedAt || 'Missing Updated At',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, InternalServerErrorException } from '@nestjs/common';

import { StepDataDto, UserSessionData, WorkflowResponseDto } from '@novu/shared';
import {
Expand Down Expand Up @@ -42,19 +42,32 @@ export class GetWorkflowUseCase {
user: UserSessionData
): Promise<StepDataDto[]> {
const stepPromises = workflow.steps.map((step: NotificationStepEntity & { _id: string }) =>
this.buildStepDataUsecase.execute(
this.buildStepForWorkflow(workflow, step, user)
);

return Promise.all(stepPromises);
}

private async buildStepForWorkflow(
workflow: WorkflowInternalResponseDto,
step: NotificationStepEntity & { _id: string },
user: UserSessionData
): Promise<StepDataDto> {
try {
return await this.buildStepDataUsecase.execute(
BuildStepDataCommand.create({
workflowIdOrInternalId: workflow._id,
stepIdOrInternalId: step._id,
user,
})
)
);

try {
return Promise.all(stepPromises);
);
} catch (error) {
throw new Error(`Failed to build full workflow steps: ${error.message}`);
throw new InternalServerErrorException({
message: 'Failed to build workflow step',
workflowId: workflow._id,
stepId: step._id,
error: error.message,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export class SyncToEnvironmentUseCase {
targetWorkflow?: WorkflowResponseDto
) {
if (targetWorkflow) {
return this.mapWorkflowToUpdateWorkflowDto(originWorkflow, targetWorkflow, preferencesToClone);
return await this.mapWorkflowToUpdateWorkflowDto(originWorkflow, targetWorkflow, preferencesToClone);
}

return this.mapWorkflowToCreateWorkflowDto(originWorkflow, preferencesToClone);
return await this.mapWorkflowToCreateWorkflowDto(originWorkflow, preferencesToClone);
}

@Instrument()
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/dto/workflows/workflow-deprecated.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { IWorkflowStepMetadata } from '../../entities/step';
import { BuilderFieldType, BuilderGroupValues, FilterParts } from '../../types';
import { MessageTemplateDto } from '../message-template';

/**
* @deprecated use DTOs from step.dto.ts
*/
export class StepVariantDto {
id?: string;
_id?: string;
Expand All @@ -24,6 +27,9 @@ export class StepVariantDto {
metadata?: IWorkflowStepMetadata;
}

/**
* @deprecated use DTOs from step.dto.ts
*/
export class NotificationStepDto extends StepVariantDto {
variants?: StepVariantDto[];
}

0 comments on commit 0302cd8

Please sign in to comment.