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-06 04:45:16 -08:00
|
|
|
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository';
|
2024-11-01 08:13:31 -07:00
|
|
|
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()
|
2024-11-06 04:45:16 -08:00
|
|
|
export class TestDefinitionsService {
|
|
|
|
constructor(private testRepository: TestDefinitionRepository) {}
|
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
|
|
|
}
|
|
|
|
}
|