Files
task-stream/libs/api/tracker/application/src/lib/automations.service.ts
Josep Piguillem 8994590b54 feat: automation rules
Owners and admins can set rules of the kind «when a ticket is created,
moves, gets assigned, gets a comment or its pull request merges; if it is
of this type, priority, area or label; then move it, assign it, label it,
change its priority, comment or put it in the active sprint». Rules act as
TaskStream within the workflow, run once per event and trigger no others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 15:53:31 +02:00

50 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { CommandBus, QueryBus } from '@nestjs/cqrs';
import {
AutomationInput,
CreateAutomationCommand,
DeleteAutomationCommand,
GetAutomationsQuery,
UpdateAutomationCommand,
} from './automations/automations';
import { Automation } from './ports/automations.repository';
/** The project's automation rules (owners and admins). */
@Injectable()
export class AutomationsService {
constructor(
private readonly commandBus: CommandBus,
private readonly queryBus: QueryBus,
) {}
list(viewerId: string, projectId: string): Promise<Automation[]> {
return this.queryBus.execute(new GetAutomationsQuery(viewerId, projectId));
}
create(
actorId: string,
projectId: string,
rule: AutomationInput,
): Promise<Automation> {
return this.commandBus.execute(
new CreateAutomationCommand(actorId, projectId, rule),
);
}
update(
actorId: string,
automationId: string,
changes: { name?: string; active?: boolean },
): Promise<Automation> {
return this.commandBus.execute(
new UpdateAutomationCommand(actorId, automationId, changes),
);
}
delete(actorId: string, automationId: string): Promise<void> {
return this.commandBus.execute(
new DeleteAutomationCommand(actorId, automationId),
);
}
}