-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
GetVault.ts
29 lines (24 loc) · 1.07 KB
/
GetVault.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
import { VaultListingInterface } from '@standardnotes/models'
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
import { ContentType, Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
export class GetVault implements SyncUseCaseInterface<VaultListingInterface> {
constructor(private items: ItemManagerInterface) {}
execute<T extends VaultListingInterface>(
query: { keySystemIdentifier: string } | { sharedVaultUuid: string },
): Result<T> {
const vaults = this.items.getItems<VaultListingInterface>(ContentType.TYPES.VaultListing)
if ('keySystemIdentifier' in query) {
const result = vaults.find((listing) => listing.systemIdentifier === query.keySystemIdentifier) as T
if (!result) {
return Result.fail('Vault not found')
}
return Result.ok(result)
} else {
const result = vaults.find((listing) => listing.sharing?.sharedVaultUuid === query.sharedVaultUuid) as T
if (!result) {
return Result.fail('Shared vault not found')
}
return Result.ok(result)
}
}
}