2024-11-01 08:13:31 -07:00
|
|
|
import { Service } from 'typedi';
|
|
|
|
|
|
|
|
import type { TestEntity } from '@/databases/entities/test-entity';
|
2024-11-04 09:51:27 -08:00
|
|
|
import type { User } from '@/databases/entities/user';
|
2024-11-01 08:13:31 -07:00
|
|
|
import { TestRepository } from '@/databases/repositories/test.repository';
|
|
|
|
import { validateEntity } from '@/generic-helpers';
|
2024-11-04 09:51:27 -08:00
|
|
|
import type { ListQuery } from '@/requests';
|
|
|
|
import { WorkflowSharingService } from '@/workflows/workflow-sharing.service';
|
2024-11-01 08:13:31 -07:00
|
|
|
|
|
|
|
@Service()
|
|
|
|
export class TestsService {
|
2024-11-04 09:51:27 -08:00
|
|
|
constructor(
|
|
|
|
private testRepository: TestRepository,
|
|
|
|
private readonly workflowSharingService: WorkflowSharingService,
|
|
|
|
) {}
|
2024-11-01 08:13:31 -07:00
|
|
|
|
|
|
|
// toEntity(attrs: { name: string; id?: string }) {
|
|
|
|
// attrs.name = attrs.name.trim();
|
|
|
|
//
|
|
|
|
// return this.testRepository.create(attrs);
|
|
|
|
// }
|
|
|
|
|
|
|
|
async save(test: TestEntity) {
|
|
|
|
await validateEntity(test);
|
|
|
|
|
|
|
|
return await this.testRepository.save(test);
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(id: string) {
|
|
|
|
return await this.testRepository.delete(id);
|
|
|
|
}
|
|
|
|
|
2024-11-04 09:51:27 -08:00
|
|
|
async getMany(user: User, options: ListQuery.Options) {
|
|
|
|
const sharedWorkflowIds = await this.workflowSharingService.getSharedWorkflowIds(user, {
|
|
|
|
scopes: ['workflow:read'],
|
2024-11-01 08:13:31 -07:00
|
|
|
});
|
|
|
|
|
2024-11-04 09:51:27 -08:00
|
|
|
return await this.testRepository.getMany(sharedWorkflowIds, options);
|
2024-11-01 08:13:31 -07:00
|
|
|
}
|
|
|
|
}
|