Skip to content

Commit

Permalink
feat: add get invoice by hash usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Oct 6, 2023
1 parent c91fc5d commit 75bc1a0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/api/src/app/wallets/get-invoice-for-wallet-by-hash.ts
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
}

0 comments on commit 75bc1a0

Please sign in to comment.