Skip to content

Commit

Permalink
feat(api): add status (#6616)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco authored Oct 8, 2024
1 parent 6740e50 commit 644c6f6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
WorkflowListResponseDto,
WorkflowOriginEnum,
WorkflowResponseDto,
WorkflowStatusEnum,
WorkflowTypeEnum,
} from '@novu/shared';
import { ControlValuesEntity, NotificationStepEntity, NotificationTemplateEntity } from '@novu/dal';
import { GetPreferencesResponseDto } from '@novu/application-generic';
Expand All @@ -31,8 +33,10 @@ export function toResponseWorkflowDto(
name: template.name,
description: template.description,
origin: template.origin || WorkflowOriginEnum.NOVU_CLOUD,
type: template.type || WorkflowTypeEnum.BRIDGE,
updatedAt: template.updatedAt || 'Missing Updated At',
createdAt: template.createdAt || 'Missing Create At',
status: WorkflowStatusEnum.ACTIVE,
};
}

Expand All @@ -52,12 +56,15 @@ function getSteps(template: NotificationTemplateEntity, controlValuesMap: { [p:

function toMinifiedWorkflowDto(template: NotificationTemplateEntity): WorkflowListResponseDto {
return {
origin: template.origin || WorkflowOriginEnum.NOVU_CLOUD,
type: template.type || WorkflowTypeEnum.BRIDGE,
_id: template._id,
name: template.name,
tags: template.tags,
updatedAt: template.updatedAt || 'Missing Updated At',
stepTypeOverviews: template.steps.map(buildStepTypeOverview).filter((stepTypeEnum) => !!stepTypeEnum),
createdAt: template.createdAt || 'Missing Create At',
status: WorkflowStatusEnum.ACTIVE,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BadRequestException, Injectable } from '@nestjs/common';

import {
ControlValuesEntity,
EnvironmentRepository,
NotificationGroupRepository,
NotificationStepEntity,
NotificationTemplateEntity,
Expand Down Expand Up @@ -58,7 +57,6 @@ export class UpsertWorkflowUseCase {
private notificationGroupRepository: NotificationGroupRepository,
private upsertPreferencesUsecase: UpsertPreferences,
private upsertControlValuesUseCase: UpsertControlValuesUseCase,
private environmentRepository: EnvironmentRepository,
private getPreferencesUseCase: GetPreferences
) {}
async execute(command: UpsertWorkflowCommand): Promise<WorkflowResponseDto> {
Expand Down
37 changes: 22 additions & 15 deletions apps/api/src/app/workflows-v2/workflow.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,23 @@ function buildErrorMsg(createWorkflowDto: Omit<WorkflowCommonsFields, '_id'>, cr

async function createWorkflowAndValidate(nameSuffix: string = ''): Promise<WorkflowResponseDto> {
const createWorkflowDto: CreateWorkflowDto = buildCreateWorkflowDto(nameSuffix);
console.log('createWorkflowDto', JSON.stringify(createWorkflowDto, null, 2));
const res = await session.testAgent.post(`${v2Prefix}/workflows`).send(createWorkflowDto);
const workflowResponseDto: WorkflowResponseDto = res.body.data;
expect(workflowResponseDto, JSON.stringify(res, null, 2)).to.be.ok;
expect(workflowResponseDto._id, JSON.stringify(res, null, 2)).to.be.ok;
expect(workflowResponseDto.updatedAt, JSON.stringify(res, null, 2)).to.be.ok;
expect(workflowResponseDto.createdAt, JSON.stringify(res, null, 2)).to.be.ok;
expect(workflowResponseDto.preferences, JSON.stringify(res, null, 2)).to.be.ok;
expect(workflowResponseDto.status, JSON.stringify(res, null, 2)).to.be.ok;
const createdWorkflowWithoutUpdateDate = removeFields(
workflowResponseDto,
'_id',
'origin',
'preferences',
'updatedAt',
'createdAt'
'createdAt',
'status',
'type'
);
createdWorkflowWithoutUpdateDate.steps = createdWorkflowWithoutUpdateDate.steps.map((step) =>
removeFields(step, 'stepUuid')
Expand Down Expand Up @@ -249,9 +251,6 @@ function buildCreateWorkflowDto(nameSuffix: string): CreateWorkflowDto {
}

async function updateWorkflowRest(id: string, workflow: UpdateWorkflowDto): Promise<WorkflowResponseDto> {
console.log(`updateWorkflow- ${id}:
${JSON.stringify(workflow, null, 2)}`);

return await safePut(`${v2Prefix}/workflows/${id}`, workflow);
}

Expand Down Expand Up @@ -296,7 +295,14 @@ function validateUpdatedWorkflowAndRemoveResponseFields(
workflowResponse: WorkflowResponseDto,
workflowUpdateRequest: UpdateWorkflowDto
): UpdateWorkflowDto {
const updatedWorkflowWoUpdated: UpdateWorkflowDto = removeFields(workflowResponse, 'updatedAt', 'origin', '_id');
const updatedWorkflowWoUpdated: UpdateWorkflowDto = removeFields(
workflowResponse,
'updatedAt',
'origin',
'_id',
'status',
'type'
);
const augmentedStep: (StepUpdateDto | StepCreateDto)[] = [];
for (const stepInResponse of workflowResponse.steps) {
expect(stepInResponse.stepUuid).to.be.ok;
Expand All @@ -318,7 +324,6 @@ async function updateWorkflowAndValidate(
updatedAt: string,
updateRequest: UpdateWorkflowDto
): Promise<void> {
console.log('updateRequest:::'.toUpperCase(), JSON.stringify(updateRequest.steps, null, 2));
const updatedWorkflow: WorkflowResponseDto = await updateWorkflowRest(id, updateRequest);
const updatedWorkflowWithResponseFieldsRemoved = validateUpdatedWorkflowAndRemoveResponseFields(
updatedWorkflow,
Expand Down Expand Up @@ -542,24 +547,19 @@ function buildInAppStepWithValues() {
}

function convertResponseToUpdateDto(workflowCreated: WorkflowResponseDto): UpdateWorkflowDto {
return removeFields(workflowCreated, 'updatedAt', '_id', 'origin') as UpdateWorkflowDto;
return removeFields(workflowCreated, 'updatedAt', '_id', 'origin', 'type', 'status') as UpdateWorkflowDto;
}

function buildUpdateDtoWithValues(workflowCreated: WorkflowResponseDto): UpdateWorkflowDto {
const updateDto = convertResponseToUpdateDto(workflowCreated);
const updatedStep = addValueToExistingStep(updateDto.steps);
const newStep = buildInAppStepWithValues();
console.log('newStep:::', JSON.stringify(newStep, null, 2));

const stoWithValues: UpdateWorkflowDto = {
return {
...updateDto,
name: `${TEST_WORKFLOW_UPDATED_NAME}-${generateUUID()}`,
steps: [updatedStep, newStep],
};

console.log('updateDto:::', JSON.stringify(stoWithValues, null, 2));

return stoWithValues;
}
function createStep(): StepCreateDto {
return {
Expand All @@ -576,7 +576,14 @@ function createStep(): StepCreateDto {

function buildUpdateRequest(workflowCreated: WorkflowResponseDto): UpdateWorkflowDto {
const steps = [createStep()];
const updateRequest = removeFields(workflowCreated, 'updatedAt', '_id', 'origin') as UpdateWorkflowDto;
const updateRequest = removeFields(
workflowCreated,
'updatedAt',
'_id',
'origin',
'status',
'type'
) as UpdateWorkflowDto;

return { ...updateRequest, name: TEST_WORKFLOW_UPDATED_NAME, steps };
}
1 change: 1 addition & 0 deletions packages/shared/src/dto/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './update-workflow-deprecated.dto';
export * from './workflow-commons-fields';
export * from './workflow-response-dto';
export * from './workflow.dto';
export * from './workflow-status-enum';
5 changes: 4 additions & 1 deletion packages/shared/src/dto/workflows/workflow-commons-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export type ListWorkflowResponse = {
totalCount: number;
};

export type WorkflowListResponseDto = Pick<WorkflowResponseDto, 'name' | 'tags' | 'updatedAt' | 'createdAt' | '_id'> & {
export type WorkflowListResponseDto = Pick<
WorkflowResponseDto,
'name' | 'tags' | 'updatedAt' | 'createdAt' | '_id' | 'status' | 'type' | 'origin'
> & {
stepTypeOverviews: StepTypeEnum[];
};

Expand Down
11 changes: 10 additions & 1 deletion packages/shared/src/dto/workflows/workflow-response-dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IsArray, IsDefined, IsEnum, IsObject, IsString } from 'class-validator';
import { PreferencesResponseDto, StepResponseDto, WorkflowCommonsFields } from './workflow-commons-fields';
import { WorkflowOriginEnum } from '../../types';
import { WorkflowOriginEnum, WorkflowTypeEnum } from '../../types';
import { WorkflowStatusEnum } from './workflow-status-enum';

export class WorkflowResponseDto extends WorkflowCommonsFields {
@IsString()
Expand All @@ -22,4 +23,12 @@ export class WorkflowResponseDto extends WorkflowCommonsFields {
@IsObject()
@IsDefined()
preferences: PreferencesResponseDto;

@IsEnum(WorkflowStatusEnum)
@IsDefined()
status: WorkflowStatusEnum;

@IsEnum(WorkflowTypeEnum)
@IsDefined()
type: WorkflowTypeEnum;
}
5 changes: 5 additions & 0 deletions packages/shared/src/dto/workflows/workflow-status-enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum WorkflowStatusEnum {
ACTIVE = 'ACTIVE',
INACTIVE = 'INACTIVE',
ERROR = 'ERROR',
}
3 changes: 1 addition & 2 deletions packages/shared/src/types/notification-templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ type ActiveIntegrationStatusWithPrimary = {
*/
export enum WorkflowTypeEnum {
REGULAR = 'REGULAR',
ECHO = 'ECHO',
ECHO = 'ECHO', // @deprecated
BRIDGE = 'BRIDGE',
}

/**
* Enum to define the origin of the workflow.
*
Expand Down

0 comments on commit 644c6f6

Please sign in to comment.