wip: renaming test definition files to have ee suffix

This commit is contained in:
Eugene Molodkin 2024-11-07 12:16:44 +01:00 committed by Oleg Ivaniv
parent 6b3f2d40d2
commit b79a7eaa4c
No known key found for this signature in database
4 changed files with 2 additions and 163 deletions

View file

@ -1,60 +0,0 @@
import type { FindManyOptions, FindOptionsWhere } from '@n8n/typeorm';
import { DataSource, In, Repository } from '@n8n/typeorm';
import { Service } from 'typedi';
import { TestDefinition } from '@/databases/entities/test-definition';
import type { ListQuery } from '@/requests';
@Service()
export class TestDefinitionRepository extends Repository<TestDefinition> {
constructor(dataSource: DataSource) {
super(TestDefinition, dataSource.manager);
}
async getMany(sharedWorkflowIds: string[], options?: ListQuery.Options) {
if (sharedWorkflowIds.length === 0) return { tests: [], count: 0 };
const where: FindOptionsWhere<TestDefinition> = {
...options?.filter,
workflow: {
id: In(sharedWorkflowIds),
},
};
const findManyOptions: FindManyOptions<TestDefinition> = {
where,
relations: ['annotationTag'],
order: { createdAt: 'DESC' },
};
if (options?.take) {
findManyOptions.skip = options.skip;
findManyOptions.take = options.take;
}
const [testDefinitions, count] = await this.findAndCount(findManyOptions);
return { testDefinitions, count };
}
async getOne(id: number, sharedWorkflowIds: string[]) {
return await this.findOne({
where: {
id,
workflow: {
id: In(sharedWorkflowIds),
},
},
relations: ['annotationTag'],
});
}
async deleteById(id: number, sharedWorkflowIds: string[]) {
return await this.delete({
id,
workflow: {
id: In(sharedWorkflowIds),
},
});
}
}

View file

@ -1,72 +0,0 @@
import { Get, Post, Patch, RestController, Delete } from '@/decorators';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { listQueryMiddleware } from '@/middlewares';
import { getSharedWorkflowIds } from '@/public-api/v1/handlers/workflows/workflows.service';
import { isPositiveInteger } from '@/utils';
import { TestDefinitionsService } from './test-definitions.service';
import { TestDefinitionsRequest } from './test-definitions.types';
@RestController('/evaluation/test-definitions')
export class TestDefinitionsController {
constructor(private readonly testsService: TestDefinitionsService) {}
@Get('/', { middlewares: listQueryMiddleware })
async getMany(req: TestDefinitionsRequest.GetMany) {
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
return await this.testsService.getMany(req.listQueryOptions, workflowIds);
}
@Get('/:id')
async getOne(req: TestDefinitionsRequest.GetOne) {
if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number');
}
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
return await this.testsService.findOne(Number(req.params.id), workflowIds);
}
@Post('/')
async create(req: TestDefinitionsRequest.Create) {
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
if (!workflowIds.includes(req.body.workflowId)) {
throw new BadRequestError('User does not have access to the workflow');
}
return await this.testsService.save(this.testsService.toEntity(req.body));
}
@Delete('/:id')
async delete(req: TestDefinitionsRequest.Delete) {
if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number');
}
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
if (workflowIds.length === 0) throw new NotFoundError('Test not found');
return await this.testsService.delete(Number(req.params.id), workflowIds);
}
@Patch('/:id')
async update(req: TestDefinitionsRequest.Update) {
if (!isPositiveInteger(req.params.id)) {
throw new BadRequestError('Test ID is not a number');
}
const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);
// Fail fast if no workflows are accessible
if (workflowIds.length === 0) throw new NotFoundError('Workflow not found');
return await this.testsService.save(
this.testsService.toEntity({ ...req.body, id: Number(req.params.id) }),
);
}
}

View file

@ -1,7 +1,7 @@
import { Service } from 'typedi';
import type { TestDefinition } from '@/databases/entities/test-definition';
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository';
import type { TestDefinition } from '@/databases/entities/test-definition.ee';
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository.ee';
import { validateEntity } from '@/generic-helpers';
import type { ListQuery } from '@/requests';

View file

@ -1,29 +0,0 @@
import type { AuthenticatedRequest, ListQuery } from '@/requests';
// ----------------------------------
// /test-definitions
// ----------------------------------
export declare namespace TestDefinitionsRequest {
namespace RouteParams {
type TestId = {
id: string;
};
}
type GetOne = AuthenticatedRequest<RouteParams.TestId>;
type GetMany = AuthenticatedRequest<{}, {}, {}, ListQuery.Params & { includeScopes?: string }> & {
listQueryOptions: ListQuery.Options;
};
type Create = AuthenticatedRequest<{}, {}, { name: string; workflowId: string }>;
type Update = AuthenticatedRequest<
RouteParams.TestId,
{},
{ name?: string; evaluationWorkflowId?: string; annotationTagId?: string }
>;
type Delete = AuthenticatedRequest<RouteParams.TestId>;
}