refactor(core): Continue moving typeorm operators to repositories (no-changelog) (#8186)

Follow-up to: #8163
This commit is contained in:
Iván Ovejero
2024-01-02 17:53:24 +01:00
committed by GitHub
parent 0ca2759d75
commit 40c1eeeddd
35 changed files with 341 additions and 354 deletions

View File

@@ -1,7 +1,4 @@
import { flags } from '@oclif/command';
import type { FindOptionsWhere } from 'typeorm';
import type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { BaseCommand } from '../BaseCommand';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
import Container from 'typedi';
@@ -43,7 +40,6 @@ export class UpdateWorkflowCommand extends BaseCommand {
return;
}
const updateQuery: QueryDeepPartialEntity<WorkflowEntity> = {};
if (flags.active === undefined) {
console.info('No update flag like "--active=true" has been set!');
return;
@@ -54,18 +50,16 @@ export class UpdateWorkflowCommand extends BaseCommand {
return;
}
updateQuery.active = flags.active === 'true';
const newState = flags.active === 'true';
const findQuery: FindOptionsWhere<WorkflowEntity> = {};
if (flags.id) {
this.logger.info(`Deactivating workflow with ID: ${flags.id}`);
findQuery.id = flags.id;
await Container.get(WorkflowRepository).updateActiveState(flags.id, newState);
} else {
this.logger.info('Deactivating all workflows');
findQuery.active = true;
await Container.get(WorkflowRepository).deactivateAll();
}
await Container.get(WorkflowRepository).update(findQuery, updateQuery);
this.logger.info('Done');
}