-
Notifications
You must be signed in to change notification settings - Fork 1
PS-469 - update query for user payment reconciliation #125
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,26 +26,37 @@ export class PaymentsService { | |
| * @throws Will throw an error if the database query fails. | ||
| */ | ||
| private async getUsersPayoutStatus(userIds: string[]) { | ||
| const usersPayoutStatus = await this.prisma.$queryRaw< | ||
| let usersPayoutStatus: { | ||
| userId: string; | ||
| setupComplete: boolean; | ||
| }[] = []; | ||
|
|
||
| if (userIds.length > 0) { | ||
| const ids = uniq(userIds); | ||
| usersPayoutStatus = await this.prisma.$queryRaw< | ||
| { | ||
| userId: string; | ||
| setupComplete: boolean; | ||
| }[] | ||
| >` | ||
| >` | ||
| WITH u(user_id) AS ( | ||
| VALUES ${Prisma.join(ids.map((id) => Prisma.sql`(${id})`))} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| ) | ||
| SELECT | ||
| upm.user_id as "userId", | ||
| u.user_id as "userId", | ||
| CASE | ||
| WHEN utx.tax_form_status = 'ACTIVE' | ||
| AND upm.status = 'CONNECTED' | ||
| AND uiv.verification_status::text = 'ACTIVE' | ||
| THEN TRUE | ||
| ELSE FALSE | ||
| END as "setupComplete" | ||
| FROM user_payment_methods upm | ||
| LEFT JOIN user_tax_form_associations utx ON upm.user_id = utx.user_id AND utx.tax_form_status = 'ACTIVE' | ||
| LEFT JOIN user_identity_verification_associations uiv ON upm.user_id = uiv.user_id | ||
| WHERE upm.user_id IN (${Prisma.join(uniq(userIds))}) | ||
| FROM u | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| LEFT JOIN user_payment_methods upm ON u.user_id = upm.user_id | ||
| LEFT JOIN user_tax_form_associations utx ON u.user_id = utx.user_id AND utx.tax_form_status = 'ACTIVE' | ||
| LEFT JOIN user_identity_verification_associations uiv ON u.user_id = uiv.user_id | ||
| `; | ||
| } | ||
|
|
||
| const setupStatusMap = { | ||
| complete: [] as string[], | ||
|
|
||
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.
[⚠️
correctness]The use of
uniqto filteruserIdsis a good practice to avoid redundant database queries. However, ensure thatuniqis imported from a reliable library likelodashto prevent potential runtime errors.