mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 00:54:06 -08:00
wip: evaluation/tests endpoint CRUD
This commit is contained in:
parent
9c98a73d2c
commit
a099769d4c
|
@ -16,7 +16,7 @@ export class TestsController {
|
||||||
async getMany(req: TestsRequest.GetMany) {
|
async getMany(req: TestsRequest.GetMany) {
|
||||||
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
|
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
|
||||||
|
|
||||||
return await this.testsService.getMany(req.user, req.listQueryOptions, workflowIds);
|
return await this.testsService.getMany(req.listQueryOptions, workflowIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
|
|
||||||
import type { TestEntity } from '@/databases/entities/test-entity';
|
import type { TestDefinition } from '@/databases/entities/test-definition';
|
||||||
import type { User } from '@/databases/entities/user';
|
import type { User } from '@/databases/entities/user';
|
||||||
import { TestRepository } from '@/databases/repositories/test.repository';
|
import { TestRepository } from '@/databases/repositories/test.repository';
|
||||||
import { validateEntity } from '@/generic-helpers';
|
import { validateEntity } from '@/generic-helpers';
|
||||||
import type { ListQuery } from '@/requests';
|
import type { ListQuery } from '@/requests';
|
||||||
import { WorkflowSharingService } from '@/workflows/workflow-sharing.service';
|
|
||||||
|
type TestDefinitionLike = Omit<
|
||||||
|
Partial<TestDefinition>,
|
||||||
|
'workflow' | 'evaluationWorkflow' | 'annotationTag'
|
||||||
|
> & {
|
||||||
|
workflow?: { id: string };
|
||||||
|
evaluationWorkflow?: { id: string };
|
||||||
|
annotationTag?: { id: string };
|
||||||
|
};
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class TestsService {
|
export class TestsService {
|
||||||
constructor(
|
constructor(private testRepository: TestRepository) {}
|
||||||
private testRepository: TestRepository,
|
|
||||||
private readonly workflowSharingService: WorkflowSharingService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
toEntity(attrs: {
|
toEntity(attrs: {
|
||||||
name?: string;
|
name?: string;
|
||||||
workflowId?: string;
|
workflowId?: string;
|
||||||
evaluationWorkflowId?: string;
|
evaluationWorkflowId?: string;
|
||||||
|
annotationTagId?: string;
|
||||||
id?: number;
|
id?: number;
|
||||||
}) {
|
}) {
|
||||||
const entity = {
|
const entity: TestDefinitionLike = {
|
||||||
name: attrs.name?.trim(),
|
name: attrs.name?.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +46,12 @@ export class TestsService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attrs.annotationTagId) {
|
||||||
|
entity.annotationTag = {
|
||||||
|
id: attrs.annotationTagId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return this.testRepository.create(entity);
|
return this.testRepository.create(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +69,7 @@ export class TestsService {
|
||||||
return await this.testRepository.deleteById(id, accessibleWorkflowIds);
|
return await this.testRepository.deleteById(id, accessibleWorkflowIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMany(user: User, options: ListQuery.Options, accessibleWorkflowIds: string[] = []) {
|
async getMany(options: ListQuery.Options, accessibleWorkflowIds: string[] = []) {
|
||||||
return await this.testRepository.getMany(accessibleWorkflowIds, options);
|
return await this.testRepository.getMany(accessibleWorkflowIds, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue