refactor(server): cli service (#9672)

This commit is contained in:
Jason Rasmussen 2024-05-22 16:23:47 -04:00 committed by GitHub
parent 967d195a05
commit 13cbdf6851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 176 additions and 91 deletions

View file

@ -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.`);