1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-27 18:13:29 +00:00

[PM-14892] Refactoring tax estimation

This commit is contained in:
Jonas Hendrickx
2024-11-18 09:12:32 +01:00
parent 16613207a2
commit 52e7c26332
7 changed files with 72 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
import { TaxIdTypesResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
export abstract class TaxServiceAbstraction {
getTaxIdTypes: () => Promise<TaxIdTypesResponse>;
getCountries: () => CountryListItem[];
/**

View File

@@ -0,0 +1,28 @@
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
export class TaxIdTypesResponse extends BaseResponse {
taxIdTypes: TaxIdTypeResponse[] = [];
constructor(response: any) {
super(response);
const taxIdTypes = this.getResponseProperty("TaxIdTypes");
if (taxIdTypes && taxIdTypes.length) {
this.taxIdTypes = taxIdTypes.map((t: any) => new TaxIdTypeResponse(t));
}
}
}
export class TaxIdTypeResponse extends BaseResponse {
code: string;
country: string;
description: string;
example: string;
constructor(response: any) {
super(response);
this.code = this.getResponseProperty("Code");
this.country = this.getResponseProperty("Country");
this.description = this.getResponseProperty("Description");
this.example = this.getResponseProperty("Example");
}
}

View File

@@ -1,8 +1,15 @@
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { TaxServiceAbstraction } from "@bitwarden/common/billing/abstractions/tax.service.abstraction";
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
import { TaxIdTypesResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
export class TaxService implements TaxServiceAbstraction {
constructor() {}
constructor(private apiService: ApiService) {}
async getTaxIdTypes(): Promise<TaxIdTypesResponse> {
const response = await this.apiService.send("GET", "/tax/id-types", null, true, true);
return new TaxIdTypesResponse(response);
}
getCountries(): CountryListItem[] {
return [