-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAccountServices.ts
57 lines (46 loc) · 2.69 KB
/
AccountServices.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { CoreId } from "@nmshd/core-types";
import { DeviceMapper, DeviceOnboardingInfoDTO } from "@nmshd/runtime";
import { MultiAccountController } from "./MultiAccountController";
import { LocalAccountDTO } from "./data/LocalAccountDTO";
import { LocalAccountMapper } from "./data/LocalAccountMapper";
export class AccountServices {
public constructor(protected readonly multiAccountController: MultiAccountController) {}
public async createAccount(name: string): Promise<LocalAccountDTO> {
const [localAccount] = await this.multiAccountController.createAccount(name);
return LocalAccountMapper.toLocalAccountDTO(localAccount);
}
public async onboardAccount(onboardingInfo: DeviceOnboardingInfoDTO, name?: string): Promise<LocalAccountDTO> {
const sharedSecret = DeviceMapper.toDeviceSharedSecret(onboardingInfo);
const [localAccount] = await this.multiAccountController.onboardDevice(sharedSecret, name);
return LocalAccountMapper.toLocalAccountDTO(localAccount);
}
public async getAccounts(): Promise<LocalAccountDTO[]> {
const localAccounts = await this.multiAccountController.getAccounts();
return localAccounts.map((account) => LocalAccountMapper.toLocalAccountDTO(account));
}
public async getAccountsInDeletion(): Promise<LocalAccountDTO[]> {
const localAccounts = await this.multiAccountController.getAccountsInDeletion();
return localAccounts.map((account) => LocalAccountMapper.toLocalAccountDTO(account));
}
public async getAccountsNotInDeletion(): Promise<LocalAccountDTO[]> {
const localAccounts = await this.multiAccountController.getAccountsNotInDeletion();
return localAccounts.map((account) => LocalAccountMapper.toLocalAccountDTO(account));
}
public async getAccount(id: string): Promise<LocalAccountDTO> {
const localAccount = await this.multiAccountController.getAccount(CoreId.from(id));
return LocalAccountMapper.toLocalAccountDTO(localAccount);
}
public async deleteAccount(id: string): Promise<void> {
await this.multiAccountController.deleteAccount(CoreId.from(id));
}
public async getAccountByAddress(address: string): Promise<LocalAccountDTO> {
const localAccount = await this.multiAccountController.getAccountByAddress(address);
return LocalAccountMapper.toLocalAccountDTO(localAccount);
}
public async clearAccounts(): Promise<void> {
await this.multiAccountController.clearAccounts();
}
public async renameAccount(localAccountId: string, newAccountName: string): Promise<void> {
await this.multiAccountController.renameLocalAccount(CoreId.from(localAccountId), newAccountName);
}
}