2024-09-12 09:07:18 -07:00
|
|
|
import type { Workflow } from 'n8n-workflow';
|
2024-01-17 09:07:34 -08:00
|
|
|
import Container from 'typedi';
|
2024-09-12 09:07:18 -07:00
|
|
|
|
2024-08-27 07:44:32 -07:00
|
|
|
import { StatisticsNames, type WorkflowStatistics } from '@/databases/entities/workflow-statistics';
|
|
|
|
import { WorkflowStatisticsRepository } from '@/databases/repositories/workflow-statistics.repository';
|
2024-01-17 09:07:34 -08:00
|
|
|
|
|
|
|
export async function createWorkflowStatisticsItem(
|
|
|
|
workflowId: Workflow['id'],
|
|
|
|
data?: Partial<WorkflowStatistics>,
|
|
|
|
) {
|
|
|
|
const entity = Container.get(WorkflowStatisticsRepository).create({
|
|
|
|
count: 0,
|
|
|
|
latestEvent: new Date().toISOString(),
|
|
|
|
name: StatisticsNames.manualSuccess,
|
|
|
|
...(data ?? {}),
|
|
|
|
workflowId,
|
|
|
|
});
|
|
|
|
|
|
|
|
await Container.get(WorkflowStatisticsRepository).insert(entity);
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|