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.

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-11-01 08:13:31 -07:00
import { Service } from 'typedi';
import type { TestEntity } from '@/databases/entities/test-entity';
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';
import { WorkflowSharingService } from '@/workflows/workflow-sharing.service';
2024-11-01 08:13:31 -07:00
@Service()
export class TestsService {
2024-11-04 09:51:27 -08:00
constructor(
private testRepository: TestRepository,
private readonly workflowSharingService: WorkflowSharingService,
) {}
2024-11-01 08:13:31 -07:00
2024-11-05 07:10:24 -08:00
toEntity(attrs: {
name?: string;
workflowId?: string;
evaluationWorkflowId?: string;
id?: number;
}) {
const entity = {
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,
};
}
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
async save(test: TestEntity) {
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-05 07:10:24 -08:00
async getMany(user: User, options: ListQuery.Options, accessibleWorkflowIds: string[] = []) {
return await this.testRepository.getMany(accessibleWorkflowIds, options);
2024-11-01 08:13:31 -07:00
}
}