refactor(core): Move more typeorm operators to repositories (no-changelog) (#8143)

Follow-up to #8139
This commit is contained in:
Iván Ovejero
2023-12-22 16:20:30 +01:00
committed by GitHub
parent 4007163651
commit a59d78de18
11 changed files with 81 additions and 55 deletions

View File

@@ -1,10 +1,39 @@
import { Service } from 'typedi';
import { DataSource, Repository } from 'typeorm';
import {
DataSource,
In,
Not,
Repository,
type DeleteResult,
type EntityManager,
type FindOptionsWhere,
Like,
} from 'typeorm';
import { CredentialsEntity } from '../entities/CredentialsEntity';
import { SharedCredentials } from '../entities/SharedCredentials';
@Service()
export class CredentialsRepository extends Repository<CredentialsEntity> {
constructor(dataSource: DataSource) {
super(CredentialsEntity, dataSource.manager);
}
async pruneSharings(
transaction: EntityManager,
credentialId: string,
userIds: string[],
): Promise<DeleteResult> {
const conditions: FindOptionsWhere<SharedCredentials> = {
credentialsId: credentialId,
userId: Not(In(userIds)),
};
return transaction.delete(SharedCredentials, conditions);
}
async findStartingWith(credentialName: string) {
return this.find({
select: ['name'],
where: { name: Like(`${credentialName}%`) },
});
}
}

View File

@@ -425,4 +425,13 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
await this.delete(batch);
} while (executionIds.length > 0);
}
async getIdsSince(date: Date) {
return this.find({
select: ['id'],
where: {
startedAt: MoreThanOrEqual(DateUtils.mixedDateToUtcDatetimeString(date)),
},
}).then((executions) => executions.map(({ id }) => id));
}
}

View File

@@ -1,5 +1,5 @@
import { Service } from 'typedi';
import { DataSource, Repository } from 'typeorm';
import { DataSource, In, Repository } from 'typeorm';
import { ExecutionData } from '../entities/ExecutionData';
@Service()
@@ -7,4 +7,13 @@ export class ExecutionDataRepository extends Repository<ExecutionData> {
constructor(dataSource: DataSource) {
super(ExecutionData, dataSource.manager);
}
async findByExecutionIds(executionIds: string[]) {
return this.find({
select: ['workflowData'],
where: {
executionId: In(executionIds),
},
}).then((executionData) => executionData.map(({ workflowData }) => workflowData));
}
}

View File

@@ -172,4 +172,11 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
return { workflows, count };
}
async findStartingWith(workflowName: string): Promise<Array<{ name: string }>> {
return this.find({
select: ['name'],
where: { name: Like(`${workflowName}%`) },
});
}
}

View File

@@ -1,5 +1,5 @@
import { Service } from 'typedi';
import { DataSource, Repository } from 'typeorm';
import { DataSource, LessThan, Repository } from 'typeorm';
import { WorkflowHistory } from '../entities/WorkflowHistory';
@Service()
@@ -7,4 +7,8 @@ export class WorkflowHistoryRepository extends Repository<WorkflowHistory> {
constructor(dataSource: DataSource) {
super(WorkflowHistory, dataSource.manager);
}
async deleteEarlierThan(date: Date) {
return this.delete({ createdAt: LessThan(date) });
}
}