mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	refactor(cli): use service instead of typeorm repo (#1423)
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
				
			|||||||
import { DomainModule } from '@app/domain';
 | 
					import { DomainModule } from '@app/domain';
 | 
				
			||||||
import { InfraModule, SystemConfigEntity } from '@app/infra';
 | 
					import { InfraModule } from '@app/infra';
 | 
				
			||||||
import { Module } from '@nestjs/common';
 | 
					import { Module } from '@nestjs/common';
 | 
				
			||||||
import { TypeOrmModule } from '@nestjs/typeorm';
 | 
					 | 
				
			||||||
import { ListUsersCommand } from './commands/list-users.command';
 | 
					import { ListUsersCommand } from './commands/list-users.command';
 | 
				
			||||||
import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './commands/password-login';
 | 
					import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './commands/password-login';
 | 
				
			||||||
import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command';
 | 
					import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command';
 | 
				
			||||||
@@ -11,7 +10,6 @@ import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/r
 | 
				
			|||||||
    DomainModule.register({
 | 
					    DomainModule.register({
 | 
				
			||||||
      imports: [InfraModule],
 | 
					      imports: [InfraModule],
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
    TypeOrmModule.forFeature([SystemConfigEntity]),
 | 
					 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  providers: [
 | 
					  providers: [
 | 
				
			||||||
    ResetAdminPasswordCommand,
 | 
					    ResetAdminPasswordCommand,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,20 +1,20 @@
 | 
				
			|||||||
import { SystemConfigEntity, SystemConfigKey } from '@app/infra';
 | 
					import { SystemConfigService } from '@app/domain';
 | 
				
			||||||
import { InjectRepository } from '@nestjs/typeorm';
 | 
					 | 
				
			||||||
import axios from 'axios';
 | 
					import axios from 'axios';
 | 
				
			||||||
import { Command, CommandRunner } from 'nest-commander';
 | 
					import { Command, CommandRunner } from 'nest-commander';
 | 
				
			||||||
import { Repository } from 'typeorm';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Command({
 | 
					@Command({
 | 
				
			||||||
  name: 'enable-password-login',
 | 
					  name: 'enable-password-login',
 | 
				
			||||||
  description: 'Enable password login',
 | 
					  description: 'Enable password login',
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class EnablePasswordLoginCommand extends CommandRunner {
 | 
					export class EnablePasswordLoginCommand extends CommandRunner {
 | 
				
			||||||
  constructor(@InjectRepository(SystemConfigEntity) private repository: Repository<SystemConfigEntity>) {
 | 
					  constructor(private configService: SystemConfigService) {
 | 
				
			||||||
    super();
 | 
					    super();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async run(): Promise<void> {
 | 
					  async run(): Promise<void> {
 | 
				
			||||||
    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');
 | 
					    await axios.post('http://localhost:3001/refresh-config');
 | 
				
			||||||
    console.log('Password login has been enabled.');
 | 
					    console.log('Password login has been enabled.');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -25,12 +25,14 @@ export class EnablePasswordLoginCommand extends CommandRunner {
 | 
				
			|||||||
  description: 'Disable password login',
 | 
					  description: 'Disable password login',
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class DisablePasswordLoginCommand extends CommandRunner {
 | 
					export class DisablePasswordLoginCommand extends CommandRunner {
 | 
				
			||||||
  constructor(@InjectRepository(SystemConfigEntity) private repository: Repository<SystemConfigEntity>) {
 | 
					  constructor(private configService: SystemConfigService) {
 | 
				
			||||||
    super();
 | 
					    super();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async run(): Promise<void> {
 | 
					  async run(): Promise<void> {
 | 
				
			||||||
    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');
 | 
					    await axios.post('http://localhost:3001/refresh-config');
 | 
				
			||||||
    console.log('Password login has been disabled.');
 | 
					    console.log('Password login has been disabled.');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user