-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add get invoice by hash usecase
- Loading branch information
1 parent
c91fc5d
commit 75bc1a0
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
core/api/src/app/wallets/get-invoice-for-wallet-by-hash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CouldNotFindWalletInvoiceError } from "@domain/errors" | ||
import { checkedToWalletId } from "@domain/wallets" | ||
import { WalletInvoicesRepository } from "@services/mongoose" | ||
|
||
export const getInvoiceForWalletByHash = async ({ | ||
walletId: uncheckedWalletId, | ||
paymentHash, | ||
}: { | ||
walletId: string | ||
paymentHash: PaymentHash | ||
}) => { | ||
const walletId = checkedToWalletId(uncheckedWalletId) | ||
if (walletId instanceof Error) return walletId | ||
|
||
const walletInvoicesRepository = WalletInvoicesRepository() | ||
|
||
const walletInvoice = await walletInvoicesRepository.findByPaymentHash(paymentHash) | ||
|
||
if (walletInvoice instanceof Error) return walletInvoice | ||
|
||
if (walletInvoice.recipientWalletDescriptor.id !== walletId) { | ||
return new CouldNotFindWalletInvoiceError() | ||
} | ||
|
||
return walletInvoice | ||
} |