1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-10 09:59:48 +01:00

PS-1620 Move AccountService.delete to Internal (#3687)

* Move AccountService.delete to Internal

* Remove unnecessary promise
This commit is contained in:
Matt Gibson 2022-10-18 16:02:11 -04:00 committed by GitHub
parent dcc0a556a2
commit da0a17a2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 44 deletions

View File

@ -1,7 +1,7 @@
import { Component } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { AccountService } from "@bitwarden/common/abstractions/account/account.service.abstraction";
import { AccountApiService } from "@bitwarden/common/abstractions/account/account-api.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
@ -23,7 +23,7 @@ export class DeleteAccountComponent {
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
private formBuilder: FormBuilder,
private accountService: AccountService,
private accountApiService: AccountApiService,
private logService: LogService
) {}
@ -34,7 +34,7 @@ export class DeleteAccountComponent {
async submit() {
try {
const verification = this.deleteForm.get("verification").value;
this.formPromise = this.accountService.delete(verification);
this.formPromise = this.accountApiService.deleteAccount(verification);
await this.formPromise;
this.platformUtilsService.showToast(
"success",

View File

@ -1,7 +1,7 @@
import { Component } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { AccountService } from "@bitwarden/common/abstractions/account/account.service.abstraction";
import { AccountApiService } from "@bitwarden/common/abstractions/account/account-api.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
@ -22,14 +22,14 @@ export class DeleteAccountComponent {
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
private formBuilder: FormBuilder,
private accountService: AccountService,
private accountApiService: AccountApiService,
private logService: LogService
) {}
async submit() {
try {
const verification = this.deleteForm.get("verification").value;
this.formPromise = this.accountService.delete(verification);
this.formPromise = this.accountApiService.deleteAccount(verification);
await this.formPromise;
this.platformUtilsService.showToast(
"success",

View File

@ -1,8 +1,11 @@
import { Injector, LOCALE_ID, NgModule } from "@angular/core";
import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service";
import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/abstractions/account/account-api.service.abstraction";
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/abstractions/account/account.service.abstraction";
import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/abstractions/account/account-api.service";
import {
InternalAccountService,
AccountService as AccountServiceAbstraction,
} from "@bitwarden/common/abstractions/account/account.service";
import { AnonymousHubService as AnonymousHubServiceAbstraction } from "@bitwarden/common/abstractions/anonymousHub.service";
import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service";
import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/abstractions/appId.service";
@ -61,8 +64,8 @@ import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction }
import { StateFactory } from "@bitwarden/common/factories/stateFactory";
import { Account } from "@bitwarden/common/models/domain/account";
import { GlobalState } from "@bitwarden/common/models/domain/global-state";
import { AccountApiService } from "@bitwarden/common/services/account/account-api.service";
import { AccountService } from "@bitwarden/common/services/account/account.service";
import { AccountApiServiceImplementation } from "@bitwarden/common/services/account/account-api.service";
import { AccountServiceImplementation } from "@bitwarden/common/services/account/account.service";
import { AnonymousHubService } from "@bitwarden/common/services/anonymousHub.service";
import { ApiService } from "@bitwarden/common/services/api.service";
import { AppIdService } from "@bitwarden/common/services/appId.service";
@ -257,18 +260,22 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction";
},
{
provide: AccountApiServiceAbstraction,
useClass: AccountApiService,
deps: [ApiServiceAbstraction],
useClass: AccountApiServiceImplementation,
deps: [
ApiServiceAbstraction,
UserVerificationServiceAbstraction,
LogService,
InternalAccountService,
],
},
{
provide: AccountServiceAbstraction,
useClass: AccountService,
deps: [
AccountApiServiceAbstraction,
UserVerificationServiceAbstraction,
MessagingServiceAbstraction,
LogService,
],
useClass: AccountServiceImplementation,
deps: [MessagingServiceAbstraction, LogService],
},
{
provide: InternalAccountService,
useExisting: AccountServiceAbstraction,
},
{ provide: LogService, useFactory: () => new ConsoleLogService(false) },
{

View File

@ -0,0 +1,5 @@
import { Verification } from "../../types/verification";
export abstract class AccountApiService {
abstract deleteAccount(verification: Verification): Promise<void>;
}

View File

@ -1,5 +0,0 @@
import { Verification } from "../../types/verification";
export abstract class AccountService {
abstract delete(verification: Verification): Promise<any>;
}

View File

@ -0,0 +1,5 @@
export abstract class AccountService {}
export abstract class InternalAccountService extends AccountService {
abstract delete(): void;
}

View File

@ -1,11 +1,26 @@
import { AccountApiService as AccountApiServiceAbstraction } from "../../abstractions/account/account-api.service.abstraction";
import { AccountApiService } from "../../abstractions/account/account-api.service";
import { InternalAccountService } from "../../abstractions/account/account.service";
import { ApiService } from "../../abstractions/api.service";
import { SecretVerificationRequest } from "../../models/request/secret-verification.request";
import { LogService } from "../../abstractions/log.service";
import { UserVerificationService } from "../../abstractions/userVerification/userVerification.service.abstraction";
import { Verification } from "../../types/verification";
export class AccountApiService implements AccountApiServiceAbstraction {
constructor(private apiService: ApiService) {}
export class AccountApiServiceImplementation implements AccountApiService {
constructor(
private apiService: ApiService,
private userVerificationService: UserVerificationService,
private logService: LogService,
private accountService: InternalAccountService
) {}
deleteAccount(request: SecretVerificationRequest): Promise<void> {
return this.apiService.send("DELETE", "/accounts", request, true, false);
async deleteAccount(verification: Verification): Promise<void> {
try {
const verificationRequest = await this.userVerificationService.buildRequest(verification);
await this.apiService.send("DELETE", "/accounts", verificationRequest, true, false);
this.accountService.delete();
} catch (e) {
this.logService.error(e);
throw e;
}
}
}

View File

@ -1,22 +1,12 @@
import { AccountApiService } from "../../abstractions/account/account-api.service.abstraction";
import { AccountService as AccountServiceAbstraction } from "../../abstractions/account/account.service.abstraction";
import { InternalAccountService } from "../../abstractions/account/account.service";
import { LogService } from "../../abstractions/log.service";
import { MessagingService } from "../../abstractions/messaging.service";
import { UserVerificationService } from "../../abstractions/userVerification/userVerification.service.abstraction";
import { Verification } from "../../types/verification";
export class AccountService implements AccountServiceAbstraction {
constructor(
private accountApiService: AccountApiService,
private userVerificationService: UserVerificationService,
private messagingService: MessagingService,
private logService: LogService
) {}
export class AccountServiceImplementation implements InternalAccountService {
constructor(private messagingService: MessagingService, private logService: LogService) {}
async delete(verification: Verification): Promise<void> {
async delete(): Promise<void> {
try {
const verificationRequest = await this.userVerificationService.buildRequest(verification);
await this.accountApiService.deleteAccount(verificationRequest);
this.messagingService.send("logout");
} catch (e) {
this.logService.error(e);