Skip to content

Commit

Permalink
Bring getAccountsInDeletion and getAccountsNotInDeletion to `Acco…
Browse files Browse the repository at this point in the history
…untServices` (#352)

* feat: add getAccountsInDeletion and getAccountsNotInDeletion to AccountServices

* refactor: simplify getAccounts* methods

* chore: test another method

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jkoenig134 and mergify[bot] authored Nov 29, 2024
1 parent 3710be4 commit 61a8882
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 10 additions & 0 deletions packages/app-runtime/src/multiAccount/AccountServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export class AccountServices {
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);
Expand Down
16 changes: 8 additions & 8 deletions packages/app-runtime/src/multiAccount/MultiAccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ export class MultiAccountController {
}

public async getAccounts(): Promise<LocalAccount[]> {
const dbAccounts = await this._localAccounts.list();
return dbAccounts.map((account) => LocalAccount.from(account));
return await this._findAccounts();
}

public async getAccountsInDeletion(): Promise<LocalAccount[]> {
const allAccounts = await this.getAccounts();
const accountsInDeletion = allAccounts.filter((item) => item.deletionDate !== undefined);
return accountsInDeletion;
return await this._findAccounts({ deletionDate: { $exists: true } });
}

public async getAccountsNotInDeletion(): Promise<LocalAccount[]> {
const allAccounts = await this.getAccounts();
const accountsNotInDeletion = allAccounts.filter((item) => item.deletionDate === undefined);
return accountsNotInDeletion;
return await this._findAccounts({ deletionDate: { $exists: false } });
}

private async _findAccounts(query?: any) {
const accounts = await this._localAccounts.find(query);
return accounts.map((account) => LocalAccount.from(account));
}

public async selectAccount(id: CoreId): Promise<[LocalAccount, AccountController]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe("MultiAccountController", function () {

afterAll(async () => await runtime.stop());

test("should get all accounts", async function () {
const accounts = await runtime.multiAccountController.getAccounts();
expect(accounts).toHaveLength(3);

const addresses = accounts.map((account) => account.address!.toString());
expect(addresses).toContain(account1.address);
expect(addresses).toContain(account2.address);
expect(addresses).toContain(account3.address);
});

test("should get all accounts in deletion", async function () {
await session1.transportServices.identityDeletionProcesses.initiateIdentityDeletionProcess();
await session2.transportServices.identityDeletionProcesses.initiateIdentityDeletionProcess();
Expand Down

0 comments on commit 61a8882

Please sign in to comment.