n8n/packages/cli/src/evaluation/tests.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-11-01 08:13:31 -07:00
import { Service } from 'typedi';
2024-11-06 03:28:23 -08:00
import type { TestDefinition } from '@/databases/entities/test-definition';
2024-11-04 09:51:27 -08:00
import type { User } from '@/databases/entities/user';
2024-11-01 08:13:31 -07:00
import { TestRepository } from '@/databases/repositories/test.repository';
import { validateEntity } from '@/generic-helpers';
2024-11-04 09:51:27 -08:00
import type { ListQuery } from '@/requests';
2024-11-06 03:28:23 -08:00
type TestDefinitionLike = Omit<
Partial<TestDefinition>,
'workflow' | 'evaluationWorkflow' | 'annotationTag'
> & {
workflow?: { id: string };
evaluationWorkflow?: { id: string };
annotationTag?: { id: string };
};
2024-11-01 08:13:31 -07:00
@Service()
export class TestsService {
2024-11-06 03:28:23 -08:00
constructor(private testRepository: TestRepository) {}
2024-11-01 08:13:31 -07:00
2024-11-05 07:10:24 -08:00
toEntity(attrs: {
name?: string;
workflowId?: string;
evaluationWorkflowId?: string;
2024-11-06 03:28:23 -08:00
annotationTagId?: string;
2024-11-05 07:10:24 -08:00
id?: number;
}) {
2024-11-06 03:28:23 -08:00
const entity: TestDefinitionLike = {
2024-11-05 07:10:24 -08:00
name: attrs.name?.trim(),
};
if (attrs.id) {
entity.id = attrs.id;
}
if (attrs.workflowId) {
entity.workflow = {
id: attrs.workflowId,
};
}
if (attrs.evaluationWorkflowId) {
entity.evaluationWorkflow = {
id: attrs.evaluationWorkflowId,
};
}
2024-11-06 03:28:23 -08:00
if (attrs.annotationTagId) {
entity.annotationTag = {
id: attrs.annotationTagId,
};
}
2024-11-05 07:10:24 -08:00
return this.testRepository.create(entity);
}
async findOne(id: number, accessibleWorkflowIds: string[]) {
return await this.testRepository.getOne(id, accessibleWorkflowIds);
}
2024-11-01 08:13:31 -07:00
2024-11-06 03:28:00 -08:00
async save(test: TestDefinition) {
2024-11-01 08:13:31 -07:00
await validateEntity(test);
return await this.testRepository.save(test);
}
2024-11-05 07:10:24 -08:00
async delete(id: number, accessibleWorkflowIds: string[]) {
return await this.testRepository.deleteById(id, accessibleWorkflowIds);
2024-11-01 08:13:31 -07:00
}
2024-11-06 03:28:23 -08:00
async getMany(options: ListQuery.Options, accessibleWorkflowIds: string[] = []) {
2024-11-05 07:10:24 -08:00
return await this.testRepository.getMany(accessibleWorkflowIds, options);
2024-11-01 08:13:31 -07:00
}
}