wip: evaluation/tests endpoint CRUD

This commit is contained in:
Eugene Molodkin 2024-11-06 12:28:23 +01:00 committed by Oleg Ivaniv
parent 9c98a73d2c
commit a099769d4c
No known key found for this signature in database
2 changed files with 21 additions and 9 deletions

View file

@ -16,7 +16,7 @@ export class TestsController {
async getMany(req: TestsRequest.GetMany) {
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')

View file

@ -1,26 +1,32 @@
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 { TestRepository } from '@/databases/repositories/test.repository';
import { validateEntity } from '@/generic-helpers';
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()
export class TestsService {
constructor(
private testRepository: TestRepository,
private readonly workflowSharingService: WorkflowSharingService,
) {}
constructor(private testRepository: TestRepository) {}
toEntity(attrs: {
name?: string;
workflowId?: string;
evaluationWorkflowId?: string;
annotationTagId?: string;
id?: number;
}) {
const entity = {
const entity: TestDefinitionLike = {
name: attrs.name?.trim(),
};
@ -40,6 +46,12 @@ export class TestsService {
};
}
if (attrs.annotationTagId) {
entity.annotationTag = {
id: attrs.annotationTagId,
};
}
return this.testRepository.create(entity);
}
@ -57,7 +69,7 @@ export class TestsService {
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);
}
}