mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): cli service (#9672)
This commit is contained in:
parent
967d195a05
commit
13cbdf6851
9 changed files with 176 additions and 91 deletions
|
|
@ -1,20 +1,9 @@
|
|||
import { Command, CommandRunner, InquirerService, Question, QuestionSet } from 'nest-commander';
|
||||
import { UserResponseDto } from 'src/dtos/user.dto';
|
||||
import { UserService } from 'src/services/user.service';
|
||||
import { CliService } from 'src/services/cli.service';
|
||||
|
||||
@Command({
|
||||
name: 'reset-admin-password',
|
||||
description: 'Reset the admin password',
|
||||
})
|
||||
export class ResetAdminPasswordCommand extends CommandRunner {
|
||||
constructor(
|
||||
private userService: UserService,
|
||||
private inquirer: InquirerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
ask = (admin: UserResponseDto) => {
|
||||
const prompt = (inquirer: InquirerService) => {
|
||||
return function ask(admin: UserResponseDto) {
|
||||
const { id, oauthId, email, name } = admin;
|
||||
console.log(`Found Admin:
|
||||
- ID=${id}
|
||||
|
|
@ -22,12 +11,25 @@ export class ResetAdminPasswordCommand extends CommandRunner {
|
|||
- Email=${email}
|
||||
- Name=${name}`);
|
||||
|
||||
return this.inquirer.ask<{ password: string }>('prompt-password', {}).then(({ password }) => password);
|
||||
return inquirer.ask<{ password: string }>('prompt-password', {}).then(({ password }) => password);
|
||||
};
|
||||
};
|
||||
|
||||
@Command({
|
||||
name: 'reset-admin-password',
|
||||
description: 'Reset the admin password',
|
||||
})
|
||||
export class ResetAdminPasswordCommand extends CommandRunner {
|
||||
constructor(
|
||||
private service: CliService,
|
||||
private inquirer: InquirerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
try {
|
||||
const { password, provided } = await this.userService.resetAdminPassword(this.ask);
|
||||
const { password, provided } = await this.service.resetAdminPassword(prompt(this.inquirer));
|
||||
|
||||
if (provided) {
|
||||
console.log(`The admin password has been updated.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue