Skip to content

Commit

Permalink
Merge pull request #4202 from novuhq/feat-trigger-event-status-enum
Browse files Browse the repository at this point in the history
feat(api): create trigger event status enum
  • Loading branch information
Pablo Fernández authored Sep 26, 2023
2 parents db88daf + ca16bfa commit 2d2e70d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/app/events/dtos/trigger-event-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IsBoolean, IsDefined, IsString } from 'class-validator';
import { TriggerEventStatusEnum } from '@novu/shared';
import { ApiProperty } from '@nestjs/swagger';

export class TriggerEventResponseDto {
Expand All @@ -11,11 +12,10 @@ export class TriggerEventResponseDto {

@ApiProperty({
description: 'Status for trigger',
enum: ['processed', 'trigger_not_active', 'subscriber_id_missing', 'error'],
enum: TriggerEventStatusEnum,
})
@IsString()
@IsDefined()
status: string;
status: TriggerEventStatusEnum;

@ApiProperty({
description: 'In case of an error, this field will contain the error message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ITenantDefine,
ReservedVariablesMap,
TriggerContextTypeEnum,
TriggerEventStatusEnum,
TriggerTenantContext,
} from '@novu/shared';

Expand Down Expand Up @@ -73,21 +74,21 @@ export class ParseEventRequest {
if (!template.active) {
return {
acknowledged: true,
status: 'trigger_not_active',
status: TriggerEventStatusEnum.NOT_ACTIVE,
};
}

if (!template.steps?.length) {
return {
acknowledged: true,
status: 'no_workflow_steps_defined',
status: TriggerEventStatusEnum.NO_WORKFLOW_STEPS,
};
}

if (!template.steps?.some((step) => step.active)) {
return {
acknowledged: true,
status: 'no_workflow_active_steps_defined',
status: TriggerEventStatusEnum.NO_WORKFLOW_ACTIVE_STEPS,
};
}

Expand All @@ -97,7 +98,7 @@ export class ParseEventRequest {
} catch (e) {
return {
acknowledged: true,
status: 'no_tenant_found',
status: TriggerEventStatusEnum.TENANT_MISSING,
};
}
}
Expand Down Expand Up @@ -135,8 +136,8 @@ export class ParseEventRequest {

return {
acknowledged: true,
status: 'processed',
transactionId: transactionId,
status: TriggerEventStatusEnum.PROCESSED,
transactionId,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Injectable } from '@nestjs/common';
import { TriggerEventStatusEnum } from '@novu/shared';

import { ProcessBulkTriggerCommand } from './process-bulk-trigger.command';

import { TriggerEventResponseDto } from '../../dtos';
import { MapTriggerRecipients } from '../map-trigger-recipients';
import { ParseEventRequestCommand } from '../parse-event-request/parse-event-request.command';
Expand Down Expand Up @@ -40,9 +43,9 @@ export class ProcessBulkTrigger {
}

result = {
status: 'error',
error: error,
acknowledged: true,
status: TriggerEventStatusEnum.ERROR,
error,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import * as _ from 'lodash';
import { SubscriberEntity, SubscriberRepository } from '@novu/dal';
import { TriggerEvent, TriggerEventCommand } from '@novu/application-generic';
import { TriggerEventStatusEnum } from '@novu/shared';

import { TriggerEventToAllCommand } from './trigger-event-to-all.command';

Expand Down Expand Up @@ -35,7 +36,7 @@ export class TriggerEventToAll {

return {
acknowledged: true,
status: 'processed',
status: TriggerEventStatusEnum.PROCESSED,
transactionId: command.transactionId,
};
}
Expand Down
11 changes: 11 additions & 0 deletions libs/shared/src/types/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { ChannelTypeEnum } from '../channel';
import { TopicKey } from '../topic';

export enum TriggerEventStatusEnum {
ERROR = 'error',
NOT_ACTIVE = 'trigger_not_active',
NO_WORKFLOW_ACTIVE_STEPS = 'no_workflow_active_steps_defined',
NO_WORKFLOW_STEPS = 'no_workflow_steps_defined',
PROCESSED = 'processed',
// TODO: Seems not used. Remove.
SUBSCRIBER_MISSING = 'subscriber_id_missing',
TENANT_MISSING = 'no_tenant_found',
}

export interface IAttachmentOptions {
mime: string;
file: Buffer;
Expand Down

1 comment on commit 2d2e70d

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.