Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nv 2405 workflows crud controller #3745

Merged
merged 13 commits into from
Jul 11, 2023
2 changes: 2 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TopicsModule } from './app/topics/topics.module';
import { InboundParseModule } from './app/inbound-parse/inbound-parse.module';
import { BlueprintModule } from './app/blueprint/blueprint.module';
import { TenantModule } from './app/tenant/tenant.module';
import { WorkflowsModule } from './app/workflows/workflows.module';

const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [
InboundParseModule,
Expand Down Expand Up @@ -59,6 +60,7 @@ const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardRefe
TopicsModule,
BlueprintModule,
TenantModule,
WorkflowsModule,
];

const providers: Provider[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { CreateNotificationTemplateQuery } from './queries';
@Controller('/notification-templates')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtAuthGuard)
@ApiTags('Workflows')
@ApiTags('Notification Templates')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to still show it in our api docs? Because 'Notification Templates' tag should be added to bootstrap. It currently shows Workflows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can show it for a few releases and then remove it later

export class NotificationTemplateController {
constructor(
private getNotificationTemplatesUsecase: GetNotificationTemplates,
Expand All @@ -57,8 +57,9 @@ export class NotificationTemplateController {
@Get('')
@ApiResponse(NotificationTemplateResponse)
@ApiOperation({
summary: 'Get workflows',
description: `Workflows were previously named notification templates`,
summary: 'Get Notification templates',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@ExternalApiAccessible()
getNotificationTemplates(
Expand All @@ -79,8 +80,9 @@ export class NotificationTemplateController {
@Put('/:templateId')
@ApiResponse(NotificationTemplateResponse)
@ApiOperation({
summary: 'Update workflow',
description: `Workflow was previously named notification template`,
summary: 'Update Notification template',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@ExternalApiAccessible()
async updateTemplateById(
Expand Down Expand Up @@ -113,8 +115,9 @@ export class NotificationTemplateController {
type: DataBooleanDto,
})
@ApiOperation({
summary: 'Delete workflow',
description: `Workflow was previously named notification template`,
summary: 'Delete Notification template',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@ExternalApiAccessible()
deleteTemplateById(@UserSession() user: IJwtPayload, @Param('templateId') templateId: string): Promise<boolean> {
Expand All @@ -131,8 +134,9 @@ export class NotificationTemplateController {
@Get('/:templateId')
@ApiResponse(NotificationTemplateResponse)
@ApiOperation({
summary: 'Get workflow',
description: `Workflow was previously named notification template`,
summary: 'Get Notification template',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@ExternalApiAccessible()
getNotificationTemplateById(
Expand All @@ -154,8 +158,9 @@ export class NotificationTemplateController {
@UseGuards(RootEnvironmentGuard)
@ApiResponse(NotificationTemplateResponse, 201)
@ApiOperation({
summary: 'Create workflow',
description: `Workflow was previously named notification template`,
summary: 'Create Notification template',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@Roles(MemberRoleEnum.ADMIN)
createNotificationTemplates(
Expand Down Expand Up @@ -188,8 +193,9 @@ export class NotificationTemplateController {
@Roles(MemberRoleEnum.ADMIN)
@ApiResponse(NotificationTemplateResponse)
@ApiOperation({
summary: 'Update workflow status',
description: `Workflow was previously named notification template`,
summary: 'Update Notification template status',
description: `Notification templates have been renamed to Workflows, Please use the new workflows controller`,
deprecated: true,
})
@ExternalApiAccessible()
changeActiveStatus(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { IsBoolean, IsDefined, IsMongoId } from 'class-validator';
import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';

/**
* DEPRECATED:
* This command is deprecated and will be removed in the future.
* Please use the ChangeWorkflowActiveStatusCommand instead.
*/
export class ChangeTemplateActiveStatusCommand extends EnvironmentWithUserCommand {
@IsBoolean()
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
import { ChangeTemplateActiveStatusCommand } from './change-template-active-status.command';
import { CreateChange, CreateChangeCommand } from '../../../change/usecases';

/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the ChangeWorkflowActiveStatus usecase instead.
*/
@Injectable()
export class ChangeTemplateActiveStatus {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ import {
IMessageAction,
IPreferenceChannels,
FilterParts,
INotificationTemplateStepMetadata,
IWorkflowStepMetadata,
} from '@novu/shared';

import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';
import { MessageTemplate } from '../../../shared/dtos/message-template';

/**
* DEPRECATED:
* This command is deprecated and will be removed in the future.
* Please use the CreateWorkflowCommand instead.
*/
export class CreateNotificationTemplateCommand extends EnvironmentWithUserCommand {
@IsMongoId()
@IsDefined()
Expand Down Expand Up @@ -112,7 +117,7 @@ export class NotificationStep {
_id?: string;

@IsOptional()
metadata?: INotificationTemplateStepMetadata;
metadata?: IWorkflowStepMetadata;
}

export class MessageFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import { CreateMessageTemplate, CreateMessageTemplateCommand } from '../../../me
import { CreateChange, CreateChangeCommand } from '../../../change/usecases';
import { ApiException } from '../../../shared/exceptions/api.exception';

/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the CreateWorkflow usecase instead.
*/
@Injectable()
export class CreateNotificationTemplate {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { DeleteMessageTemplateCommand } from '../../../message-template/usecases
import { DeleteMessageTemplate } from '../../../message-template/usecases/delete-message-template/delete-message-template.usecase';
import { GetNotificationTemplateCommand } from '../get-notification-template/get-notification-template.command';

/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the DeleteWorkflow usecase instead.
*/
@Injectable()
export class DeleteNotificationTemplate {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { IsDefined, IsMongoId } from 'class-validator';
import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';

/**
* DEPRECATED:
* This command is deprecated and will be removed in the future.
* Please use the GetWorkflowCommand instead.
*/
export class GetNotificationTemplateCommand extends EnvironmentWithUserCommand {
@IsDefined()
@IsMongoId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { NotificationTemplateEntity, NotificationTemplateRepository } from '@novu/dal';
import { GetNotificationTemplateCommand } from './get-notification-template.command';

/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the GetWorkflow usecase instead.
*/
@Injectable()
export class GetNotificationTemplate {
constructor(private notificationTemplateRepository: NotificationTemplateRepository) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { IsNumber } from 'class-validator';

import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';

/**
* DEPRECATED:
* This command is deprecated and will be removed in the future.
* Please use the GetWorkflowsCommand instead.
*/
export class GetNotificationTemplatesCommand extends EnvironmentWithUserCommand {
@IsNumber()
page: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Injectable } from '@nestjs/common';
import { NotificationTemplateRepository } from '@novu/dal';
import { GetNotificationTemplatesCommand } from './get-notification-templates.command';
import { NotificationTemplatesResponseDto } from '../../dto/notification-templates.response.dto';
/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the GetWorkflows usecase instead.
*/
@Injectable()
export class GetNotificationTemplates {
constructor(private notificationTemplateRepository: NotificationTemplateRepository) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { IPreferenceChannels } from '@novu/shared';
import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';
import { NotificationStep } from '../create-notification-template';

/**
* DEPRECATED:
* This command is deprecated and will be removed in the future.
* Please use the UpdateWorkflowCommand instead.
*/
export class UpdateNotificationTemplateCommand extends EnvironmentWithUserCommand {
@IsDefined()
@IsMongoId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import { NotificationStep } from '../create-notification-template';
import { DeleteMessageTemplate } from '../../../message-template/usecases/delete-message-template/delete-message-template.usecase';
import { DeleteMessageTemplateCommand } from '../../../message-template/usecases/delete-message-template/delete-message-template.command';

/**
* DEPRECATED:
* This usecase is deprecated and will be removed in the future.
* Please use the UpdateWorkflow usecase instead.
*/
@Injectable()
export class UpdateNotificationTemplate {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/shared/dtos/notification-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DigestUnitEnum,
DigestTypeEnum,
DelayTypeEnum,
INotificationTemplateStepMetadata,
IWorkflowStepMetadata,
IDigestBaseMetadata,
IDigestRegularMetadata,
IDigestTimedMetadata,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class NotificationStep {
{ $ref: getSchemaPath(DelayScheduledMetadata) },
],
})
metadata?: INotificationTemplateStepMetadata;
metadata?: IWorkflowStepMetadata;

@ApiPropertyOptional()
replyCallback?: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsDefined } from 'class-validator';

export class ChangeWorkflowStatusRequestDto {
@ApiProperty()
@IsDefined()
@IsBoolean()
active: boolean;
}
65 changes: 65 additions & 0 deletions apps/api/src/app/workflows/dto/create-workflow-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IsArray, IsBoolean, IsDefined, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ICreateNotificationTemplateDto, IPreferenceChannels } from '@novu/shared';

import { PreferenceChannels } from '../../shared/dtos/preference-channels';
import { NotificationStep } from '../../shared/dtos/notification-step';

export class CreateWorkflowRequestDto implements ICreateNotificationTemplateDto {
@ApiProperty()
@IsString()
@IsDefined()
name: string;

@ApiProperty()
@IsString()
@IsDefined({
message: 'Notification group must be provided ',
})
notificationGroupId: string;

@ApiPropertyOptional()
@IsOptional()
@IsArray()
tags: string[];

@ApiPropertyOptional()
@IsString()
@IsOptional()
@MaxLength(100)
description: string;

@ApiProperty({
type: [NotificationStep],
})
@IsDefined()
@IsArray()
@ValidateNested()
steps: NotificationStep[];

@ApiPropertyOptional()
@IsBoolean()
@IsOptional()
active?: boolean;

@ApiPropertyOptional()
@IsBoolean()
@IsOptional()
draft?: boolean;

@ApiPropertyOptional()
@IsBoolean()
@IsOptional()
critical?: boolean;

@ApiPropertyOptional({
type: PreferenceChannels,
})
@IsOptional()
preferenceSettings?: IPreferenceChannels;

@ApiPropertyOptional()
@IsOptional()
@IsString()
blueprintId?: string;
}
3 changes: 3 additions & 0 deletions apps/api/src/app/workflows/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './change-workflow-status-request.dto';
export * from './create-workflow-request.dto';
export * from './update-workflow-request.dto';
50 changes: 50 additions & 0 deletions apps/api/src/app/workflows/dto/update-workflow-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { IsArray, IsMongoId, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator';
import { ICreateNotificationTemplateDto, IPreferenceChannels } from '@novu/shared';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { PreferenceChannels } from '../../shared/dtos/preference-channels';
import { NotificationStep } from '../../shared/dtos/notification-step';

export class UpdateWorkflowRequestDto implements ICreateNotificationTemplateDto {
@ApiProperty()
@IsString()
@IsOptional()
name: string;

@ApiPropertyOptional()
@IsArray()
@IsOptional()
tags: string[];

@ApiPropertyOptional()
@IsString()
@IsOptional()
@MaxLength(300)
description: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
identifier?: string;

@ApiPropertyOptional()
@IsArray()
@IsOptional()
@ValidateNested()
steps: NotificationStep[];

@ApiProperty()
@IsOptional()
@IsMongoId()
notificationGroupId: string;

@ApiPropertyOptional()
active?: boolean;

@ApiPropertyOptional()
critical?: boolean;

@ApiPropertyOptional({
type: PreferenceChannels,
})
preferenceSettings?: IPreferenceChannels;
}