-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(backend): add clientId to OP resources #535
Conversation
a005758
to
04f9d1b
Compare
packages/backend/migrations/20220228162503_create_incoming_payments_table.js
Outdated
Show resolved
Hide resolved
packages/backend/src/open_payments/payment/incoming/routes.test.ts
Outdated
Show resolved
Hide resolved
description?: string | ||
expiresAt?: Date | ||
incomingAmount?: Amount | ||
externalRef?: string | ||
} | ||
|
||
export interface IncomingPaymentService { | ||
get(id: string): Promise<IncomingPayment | undefined> | ||
get(id: string, clientId?: string): Promise<IncomingPayment | undefined> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get(id: string, clientId?: string): Promise<IncomingPayment | undefined> | |
get(id: string): Promise<IncomingPayment | undefined> |
What if the clientId
check is moved out to the calling routes functions?
I'm thinking however/wherever we check clientId
is where we'll also check the payment pointer, both of which are only relevant to the routes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which check are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching the clientId
(and paymentPointerId
)
What if incomingPaymentService.get
still just took the id
, and IncomingPaymentRoutes.get
would check the clientId
(and paymentPointerId
) of the returned incoming payment.
packages/backend/src/open_payments/payment/incoming/service.test.ts
Outdated
Show resolved
Hide resolved
packages/backend/src/open_payments/grantReference/service.test.ts
Outdated
Show resolved
Hide resolved
packages/backend/src/open_payments/grantReference/service.test.ts
Outdated
Show resolved
Hide resolved
await grantReferenceService.lock(grantRef.id, trx) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
await new Promise((f: any) => setTimeout(f, 6000)) | ||
await grantReferenceService.get(grantRef.id, trx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also just lock it and then do
await expect(grantReferenceService.get(grantRef.id, trx).skipLocked()).resolves.toBeUndefined()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is probably the faster version. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I can't do skipedLocked
on the get
method, instead I put
await GrantReference.transaction(async (trx) => {
await grantReferenceService.lock(grantRef.id, trx)
await expect(
GrantReference.query(trx).findById(grantRef.id).skipLocked()
).resolves.toBeUndefined()
})
However, that resulted in Rejected to value: [Error: .skipLocked() can only be used after a call to .forShare() or .forUpdate()!]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add one of those to query or just leave the test as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That also didn't work. It queries it successfully. It probably has to do with the fact that we can't do forNoKeyUpdate()
using objection. I'll just leave it as is.
options: CreateGrantReferenceOptions, | ||
trx?: Transaction | ||
): Promise<GrantReference> | ||
lock(grantId: string, trx: TransactionOrKnex): Promise<void> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lock(grantId: string, trx: TransactionOrKnex): Promise<void> | |
lock(grantId: string, trx: Transaction): Promise<void> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has implications on the validateGrant
function in the OutgoingPaymentService
. Right now, one of its input parameters is deps:ServiceDependencies
, which includes deps.knex:TransactionOrKnex
. If we don't want to use that, I have to specifically pass the transaction to validateGrant
. Do you think we should make that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes proposed in this pull request
Context
Checklist
fixes #number