Skip to content

Commit

Permalink
update createDotsTransferAction to use ProgramEnrollment.dotsUserId
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Nov 15, 2024
1 parent a40bf59 commit 5c339d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 16 additions & 3 deletions apps/web/lib/actions/partners/create-dots-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { authActionClient } from "../safe-action";

const schema = z.object({
workspaceId: z.string(),
dotsUserId: z.string(),
payoutId: z.string(),
});

export const createDotsTransferAction = authActionClient
.schema(schema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
const { dotsUserId, payoutId } = parsedInput;
const { payoutId } = parsedInput;

if (!workspace.dotsAppId) {
throw new Error("Dots app not found for workspace");
Expand All @@ -26,11 +25,25 @@ export const createDotsTransferAction = authActionClient
where: { id: payoutId },
});

const programEnrollment = await prisma.programEnrollment.findUniqueOrThrow({
where: {
partnerId_programId: {
partnerId: payout.partnerId,
programId: payout.programId,
},
},
select: { dotsUserId: true },
});

if (!programEnrollment.dotsUserId) {
throw new Error("Partner is not properly enrolled in this program");
}

const [transfer, orgTransfer] = await Promise.all([
createTransfer({
amount: payout.amount,
dotsAppId: workspace.dotsAppId,
dotsUserId,
dotsUserId: programEnrollment.dotsUserId,
}),
createOrgTransfer({
amount: payout.fee,
Expand Down
1 change: 0 additions & 1 deletion apps/web/ui/partners/payout-details-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ function PayoutDetailsSheetContent({
}
await executeAsync({
workspaceId: workspaceId!,
dotsUserId: payout.partner.dotsUserId,
payoutId: payout.id,
});
}}
Expand Down

0 comments on commit 5c339d9

Please sign in to comment.