feat(backend): Automatisierungen mit drei fest hinterlegten Triggern (Modul 30)
Neues AutomationModule mit AutomationRule-Modell (ein Row je Trigger-Typ, per Unique Constraint erzwungen). Drei fest im Code hinterlegte Trigger, die Admins nur aktivieren/deaktivieren bzw. deren Konfiguration/Aufgaben- text anpassen können: - QUEENLESS_NO_EGGS: Königin nicht gesehen UND keine Stifte vorhanden (bei Durchsicht) → Kontrollaufgabe - VARROA_THRESHOLD: Varroa-Schwellenwert überschritten (konfigurierbar, Standard 10 Milben/Tag) → Behandlungsprüfung - FEED_STATUS_CRITICAL: Futterstatus "kritisch" (bei Durchsicht) → Fütterungsaufgabe Jeder ausgelöste Trigger erzeugt eine Task UND eine Notification sowie einen Audit-Log-Eintrag; Tasks lösen zusätzlich das bestehende task.created-Webhook aus. InspectionsService und VarroaService rufen die Auswertung direkt nach dem jeweiligen Erstellen auf. Neue Endpunkte (nur Administrator): GET/PATCH /automation-rules. Unit-Tests für AutomationService (alle drei Trigger, Deaktivierung, Update mit Audit-Log) sowie E2E-Tests (Rollen-Check, alle drei Trigger end-to-end über echte Inspection-/Varroa-Endpunkte, Deaktivierung verhindert weitere Trigger). E2E-Suite zweimal hintereinander grün verifiziert (Idempotenz der globalen Regel-Zeilen sichergestellt). Migration auf Dev- und Test-Datenbank angewendet.
This commit is contained in:
1 parent
42a2be31b4
commit
3f47a6ae8d
15 files changed
+733
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AutomationModule } from '../automation/automation.module';
|
||||
import { InspectionsController } from './inspections.controller';
|
||||
import { ColonyInspectionsController } from './colony-inspections.controller';
|
||||
import { InspectionsService } from './inspections.service';
|
||||
|
||||
@Module({
|
||||
imports: [AutomationModule],
|
||||
controllers: [InspectionsController, ColonyInspectionsController],
|
||||
providers: [InspectionsService],
|
||||
exports: [InspectionsService],
|
||||
|
||||
@@ -2,6 +2,7 @@ import { NotFoundException } from '@nestjs/common';
|
||||
import { InspectionsService } from './inspections.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { WebhooksService } from '../webhooks/webhooks.service';
|
||||
import { AutomationService } from '../automation/automation.service';
|
||||
|
||||
describe('InspectionsService', () => {
|
||||
let service: InspectionsService;
|
||||
@@ -30,9 +31,13 @@ describe('InspectionsService', () => {
|
||||
task: { create: jest.fn() },
|
||||
};
|
||||
const webhooks = { dispatch: jest.fn().mockResolvedValue(undefined) };
|
||||
const automation = {
|
||||
evaluateInspection: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
service = new InspectionsService(
|
||||
prisma as unknown as PrismaService,
|
||||
webhooks as unknown as WebhooksService,
|
||||
automation as unknown as AutomationService,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { WebhooksService } from '../webhooks/webhooks.service';
|
||||
import { AutomationService } from '../automation/automation.service';
|
||||
import { Inspection, Task } from '../../generated/prisma';
|
||||
import { CreateInspectionDto } from './dto/create-inspection.dto';
|
||||
import { CreateTaskFromInspectionDto } from './dto/create-task-from-inspection.dto';
|
||||
@@ -10,6 +11,7 @@ export class InspectionsService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly webhooks: WebhooksService,
|
||||
private readonly automation: AutomationService,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Inspection[]> {
|
||||
@@ -41,6 +43,7 @@ export class InspectionsService {
|
||||
data: { ...dto, date: new Date(dto.date), userId: actingUserId },
|
||||
});
|
||||
await this.webhooks.dispatch('inspection.created', inspection);
|
||||
await this.automation.evaluateInspection(inspection);
|
||||
return inspection;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user