feat(automations): parallel branch canvas, simple/advanced level per org, rules list UX
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import type {
|
||||
AutomationAction,
|
||||
AutomationChainMode,
|
||||
AutomationConditionField,
|
||||
AutomationConditionOp,
|
||||
AutomationNotifyChannel,
|
||||
@@ -19,6 +20,7 @@ import type {
|
||||
import {
|
||||
MAX_AUTOMATION_STEPS,
|
||||
automationStepToConfig,
|
||||
automationUsesAdvanced,
|
||||
firstAutomationAction,
|
||||
matchFormFieldCondition,
|
||||
normalizeAutomationSteps,
|
||||
@@ -95,6 +97,7 @@ export class AutomationsService {
|
||||
const action = firstAutomationAction(steps);
|
||||
if (!action) throw new BadRequestException('حداقل یک عمل لازم است');
|
||||
await this.assertStepRefs(organizationId, steps);
|
||||
await this.assertLevelAllows(organizationId, steps, chainExtra(dto.config).chainMode);
|
||||
const row = await this.prisma.automationRule.create({
|
||||
data: {
|
||||
organizationId,
|
||||
@@ -130,7 +133,14 @@ export class AutomationsService {
|
||||
if (steps && !nextAction) {
|
||||
throw new BadRequestException('حداقل یک عمل لازم است');
|
||||
}
|
||||
if (steps) await this.assertStepRefs(organizationId, steps);
|
||||
if (steps) {
|
||||
await this.assertStepRefs(organizationId, steps);
|
||||
await this.assertLevelAllows(
|
||||
organizationId,
|
||||
steps,
|
||||
chainExtra(dto.config ?? asConfig(existing.config)).chainMode,
|
||||
);
|
||||
}
|
||||
|
||||
const row = await this.prisma.automationRule.update({
|
||||
where: { id },
|
||||
@@ -487,6 +497,23 @@ export class AutomationsService {
|
||||
}
|
||||
}
|
||||
|
||||
private async assertLevelAllows(
|
||||
organizationId: string,
|
||||
steps: AutomationStep[],
|
||||
chainMode: AutomationChainMode | undefined,
|
||||
) {
|
||||
if (!automationUsesAdvanced(steps, chainMode)) return;
|
||||
const org = await this.prisma.organization.findUnique({
|
||||
where: { id: organizationId },
|
||||
select: { enabledModules: true },
|
||||
});
|
||||
if (!org?.enabledModules.includes('workflow_automations_advanced')) {
|
||||
throw new BadRequestException(
|
||||
'شاخهها، شرط روی پاسخ فرم و تقسیم نوبتی فقط در اتوماسیون حرفهای فعال است',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async executeNotify(
|
||||
title: string,
|
||||
config: AutomationRuleConfig,
|
||||
|
||||
Reference in New Issue
Block a user