File size: 579 Bytes
aec3094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { WorkflowRepository } from '@n8n/db';
import { Service } from '@n8n/di';
import { UnexpectedError, type IWorkflowBase, type IWorkflowLoader } from 'n8n-workflow';

@Service()
export class WorkflowLoaderService implements IWorkflowLoader {
	constructor(private readonly workflowRepository: WorkflowRepository) {}

	async get(workflowId: string): Promise<IWorkflowBase> {
		const workflow = await this.workflowRepository.findById(workflowId);

		if (!workflow) {
			throw new UnexpectedError(`Failed to find workflow with ID "${workflowId}"`);
		}

		return workflow;
	}
}