110 lines
1.8 KiB
TypeScript
110 lines
1.8 KiB
TypeScript
import { Type } from 'class-transformer';
|
|
import {
|
|
IsBoolean,
|
|
IsIn,
|
|
IsInt,
|
|
IsObject,
|
|
IsOptional,
|
|
IsString,
|
|
MaxLength,
|
|
Min,
|
|
MinLength,
|
|
ValidateIf,
|
|
} from 'class-validator';
|
|
|
|
const TRIGGERS = [
|
|
'person_created',
|
|
'lead_submitted',
|
|
'deal_created',
|
|
'deal_stage_changed',
|
|
'deal_won',
|
|
'deal_lost',
|
|
'ticket_created',
|
|
'ticket_resolved',
|
|
'invoice_issued',
|
|
'invoice_paid',
|
|
'activity_done',
|
|
] as const;
|
|
const ACTIONS = [
|
|
'create_activity',
|
|
'create_notification',
|
|
'add_loyalty_points',
|
|
] as const;
|
|
|
|
export class CreateAutomationRuleDto {
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(120)
|
|
name!: string;
|
|
|
|
@IsIn(TRIGGERS)
|
|
trigger!: (typeof TRIGGERS)[number];
|
|
|
|
@IsIn(ACTIONS)
|
|
action!: (typeof ACTIONS)[number];
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isActive?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsObject()
|
|
config?: Record<string, unknown>;
|
|
}
|
|
|
|
export class UpdateAutomationRuleDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(120)
|
|
name?: string;
|
|
|
|
@IsOptional()
|
|
@IsIn(TRIGGERS)
|
|
trigger?: (typeof TRIGGERS)[number];
|
|
|
|
@IsOptional()
|
|
@IsIn(ACTIONS)
|
|
action?: (typeof ACTIONS)[number];
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isActive?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsObject()
|
|
config?: Record<string, unknown>;
|
|
}
|
|
|
|
export class AutomationConfigDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(200)
|
|
title?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(1000)
|
|
body?: string;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((_, v) => v !== '' && v != null)
|
|
@IsString()
|
|
assigneeId?: string | null;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((_, v) => v !== '' && v != null)
|
|
@IsString()
|
|
notifyUserId?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsIn(['call', 'meeting', 'task', 'note'])
|
|
activityType?: string;
|
|
|
|
@IsOptional()
|
|
@Type(() => Number)
|
|
@IsInt()
|
|
@Min(1)
|
|
points?: number;
|
|
}
|