wip: rename Test to TestDefinition

This commit is contained in:
Eugene Molodkin 2024-11-06 13:45:16 +01:00 committed by Oleg Ivaniv
parent a099769d4c
commit f61653f2e2
No known key found for this signature in database
4 changed files with 18 additions and 19 deletions

View file

@ -6,7 +6,7 @@ import { TestDefinition } from '@/databases/entities/test-definition';
import type { ListQuery } from '@/requests'; import type { ListQuery } from '@/requests';
@Service() @Service()
export class TestRepository extends Repository<TestDefinition> { export class TestDefinitionRepository extends Repository<TestDefinition> {
constructor(dataSource: DataSource) { constructor(dataSource: DataSource) {
super(TestDefinition, dataSource.manager); super(TestDefinition, dataSource.manager);
} }
@ -32,9 +32,9 @@ export class TestRepository extends Repository<TestDefinition> {
findManyOptions.take = options.take; findManyOptions.take = options.take;
} }
const [tests, count] = await this.findAndCount(findManyOptions); const [testDefinitions, count] = await this.findAndCount(findManyOptions);
return { tests, count }; return { testDefinitions, count };
} }
async getOne(id: number, sharedWorkflowIds: string[]) { async getOne(id: number, sharedWorkflowIds: string[]) {

View file

@ -5,22 +5,22 @@ import { listQueryMiddleware } from '@/middlewares';
import { getSharedWorkflowIds } from '@/public-api/v1/handlers/workflows/workflows.service'; import { getSharedWorkflowIds } from '@/public-api/v1/handlers/workflows/workflows.service';
import { isPositiveInteger } from '@/utils'; import { isPositiveInteger } from '@/utils';
import { TestsService } from './tests.service'; import { TestDefinitionsService } from './test-definitions.service';
import { TestsRequest } from './tests.types'; import { TestDefinitionsRequest } from './test-definitions.types';
@RestController('/evaluation/tests') @RestController('/evaluation/test-definitions')
export class TestsController { export class TestDefinitionsController {
constructor(private readonly testsService: TestsService) {} constructor(private readonly testsService: TestDefinitionsService) {}
@Get('/', { middlewares: listQueryMiddleware }) @Get('/', { middlewares: listQueryMiddleware })
async getMany(req: TestsRequest.GetMany) { async getMany(req: TestDefinitionsRequest.GetMany) {
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']); const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
return await this.testsService.getMany(req.listQueryOptions, workflowIds); return await this.testsService.getMany(req.listQueryOptions, workflowIds);
} }
@Get('/:id') @Get('/:id')
async getOne(req: TestsRequest.GetOne) { async getOne(req: TestDefinitionsRequest.GetOne) {
if (!isPositiveInteger(req.params.id)) { if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number'); throw new BadRequestError('Test ID is not a number');
} }
@ -31,7 +31,7 @@ export class TestsController {
} }
@Post('/') @Post('/')
async create(req: TestsRequest.Create) { async create(req: TestDefinitionsRequest.Create) {
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']); const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
if (!workflowIds.includes(req.body.workflowId)) { if (!workflowIds.includes(req.body.workflowId)) {
@ -42,7 +42,7 @@ export class TestsController {
} }
@Delete('/:id') @Delete('/:id')
async delete(req: TestsRequest.Delete) { async delete(req: TestDefinitionsRequest.Delete) {
if (!isPositiveInteger(req.params.id)) { if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number'); throw new BadRequestError('Test ID is not a number');
} }
@ -55,7 +55,7 @@ export class TestsController {
} }
@Patch('/:id') @Patch('/:id')
async update(req: TestsRequest.Update) { async update(req: TestDefinitionsRequest.Update) {
if (!isPositiveInteger(req.params.id)) { if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number'); throw new BadRequestError('Test ID is not a number');
} }

View file

@ -1,8 +1,7 @@
import { Service } from 'typedi'; import { Service } from 'typedi';
import type { TestDefinition } from '@/databases/entities/test-definition'; import type { TestDefinition } from '@/databases/entities/test-definition';
import type { User } from '@/databases/entities/user'; import { TestDefinitionRepository } from '@/databases/repositories/test-definition.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';
@ -16,8 +15,8 @@ type TestDefinitionLike = Omit<
}; };
@Service() @Service()
export class TestsService { export class TestDefinitionsService {
constructor(private testRepository: TestRepository) {} constructor(private testRepository: TestDefinitionRepository) {}
toEntity(attrs: { toEntity(attrs: {
name?: string; name?: string;

View file

@ -1,10 +1,10 @@
import type { AuthenticatedRequest, ListQuery } from '@/requests'; import type { AuthenticatedRequest, ListQuery } from '@/requests';
// ---------------------------------- // ----------------------------------
// /tests // /test-definitions
// ---------------------------------- // ----------------------------------
export declare namespace TestsRequest { export declare namespace TestDefinitionsRequest {
namespace RouteParams { namespace RouteParams {
type TestId = { type TestId = {
id: string; id: string;