From b1311547b271855bbaec84e5fdedd4a7431cf685 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 26 Jan 2023 09:30:33 -0500 Subject: [PATCH] refactor(cli): use service instead of typeorm repo (#1423) --- server/apps/cli/src/app.module.ts | 4 +--- server/apps/cli/src/commands/password-login.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/apps/cli/src/app.module.ts b/server/apps/cli/src/app.module.ts index e38c2d749d..142ead9b91 100644 --- a/server/apps/cli/src/app.module.ts +++ b/server/apps/cli/src/app.module.ts @@ -1,7 +1,6 @@ import { DomainModule } from '@app/domain'; -import { InfraModule, SystemConfigEntity } from '@app/infra'; +import { InfraModule } from '@app/infra'; import { Module } from '@nestjs/common'; -import { TypeOrmModule } from '@nestjs/typeorm'; import { ListUsersCommand } from './commands/list-users.command'; import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './commands/password-login'; import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command'; @@ -11,7 +10,6 @@ import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/r DomainModule.register({ imports: [InfraModule], }), - TypeOrmModule.forFeature([SystemConfigEntity]), ], providers: [ ResetAdminPasswordCommand, diff --git a/server/apps/cli/src/commands/password-login.ts b/server/apps/cli/src/commands/password-login.ts index dd464e32c3..8cd1276bc0 100644 --- a/server/apps/cli/src/commands/password-login.ts +++ b/server/apps/cli/src/commands/password-login.ts @@ -1,20 +1,20 @@ -import { SystemConfigEntity, SystemConfigKey } from '@app/infra'; -import { InjectRepository } from '@nestjs/typeorm'; +import { SystemConfigService } from '@app/domain'; import axios from 'axios'; import { Command, CommandRunner } from 'nest-commander'; -import { Repository } from 'typeorm'; @Command({ name: 'enable-password-login', description: 'Enable password login', }) export class EnablePasswordLoginCommand extends CommandRunner { - constructor(@InjectRepository(SystemConfigEntity) private repository: Repository) { + constructor(private configService: SystemConfigService) { super(); } async run(): Promise { - await this.repository.delete({ key: SystemConfigKey.PASSWORD_LOGIN_ENABLED }); + const config = await this.configService.getConfig(); + config.passwordLogin.enabled = true; + await this.configService.updateConfig(config); await axios.post('http://localhost:3001/refresh-config'); console.log('Password login has been enabled.'); } @@ -25,12 +25,14 @@ export class EnablePasswordLoginCommand extends CommandRunner { description: 'Disable password login', }) export class DisablePasswordLoginCommand extends CommandRunner { - constructor(@InjectRepository(SystemConfigEntity) private repository: Repository) { + constructor(private configService: SystemConfigService) { super(); } async run(): Promise { - await this.repository.save({ key: SystemConfigKey.PASSWORD_LOGIN_ENABLED, value: false }); + const config = await this.configService.getConfig(); + config.passwordLogin.enabled = false; + await this.configService.updateConfig(config); await axios.post('http://localhost:3001/refresh-config'); console.log('Password login has been disabled.'); }