Skip to content

Commit 6085e27

Browse files
authored
Merge pull request #997 from PayButton/fix/user-from-trigger
fix: fetch user from trigger fix
2 parents a6763af + b7a3102 commit 6085e27

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

services/triggerService.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,32 +300,24 @@ export async function executeAddressTriggers (broadcastTxData: BroadcastTxData,
300300
}
301301

302302
async function fetchUserFromTriggerId (triggerId: string): Promise<UserProfile> {
303-
const result = await prisma.paybuttonTrigger.findUniqueOrThrow({
304-
where: { id: triggerId },
305-
select: {
306-
paybutton: {
307-
select: {
308-
addresses: {
309-
select: {
310-
address: {
311-
select: {
312-
userProfiles: {
313-
select: {
314-
userProfile: true
315-
}
316-
}
317-
}
318-
}
319-
}
320-
}
303+
const pb = await prisma.paybutton.findFirstOrThrow({
304+
where: {
305+
triggers: {
306+
some: {
307+
id: triggerId
321308
}
322309
}
310+
},
311+
select: {
312+
providerUserId: true
323313
}
324314
})
325315

326-
// Since there may be multiple user profiles linked, extract the first one if needed
327-
const userProfile = result.paybutton.addresses[0].address.userProfiles[0].userProfile
328-
return userProfile
316+
return await prisma.userProfile.findUniqueOrThrow({
317+
where: {
318+
id: pb.providerUserId
319+
}
320+
})
329321
}
330322

331323
async function decrementUserCreditCount (userId: string): Promise<void> {

0 commit comments

Comments
 (0)