Skip to content

Commit

Permalink
♻️ (auth) Group join workspaces queries in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jan 28, 2023
1 parent d54822a commit bfd85b4
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions apps/builder/src/features/auth/api/joinWorkspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ export const joinWorkspaces = async (
{ id, email }: { id: string; email: string },
invitations: WorkspaceInvitation[]
) => {
await p.memberInWorkspace.createMany({
data: invitations.map((invitation) => ({
workspaceId: invitation.workspaceId,
role: invitation.type,
userId: id,
})),
})
return p.workspaceInvitation.deleteMany({
where: {
email,
},
})
await p.$transaction([
p.memberInWorkspace.createMany({
data: invitations.map((invitation) => ({
workspaceId: invitation.workspaceId,
role: invitation.type,
userId: id,
})),
}),
p.workspaceInvitation.deleteMany({
where: {
email,
},
}),
])
}

0 comments on commit bfd85b4

Please sign in to comment.