Fix/accept team invite once signup (#1653)

* Accept team invite once signup

* Add expectations for the team invite

Co-authored-by: Miguel Nieto A <[email protected]>
This commit is contained in:
Alex van AndelandMiguel Nieto A authored and GitHub committed 2022-01-29 18:56:40 +00:00
1 parent 2079199bab
commit 9dc45071c5
2 files changed
+27 -1

No files matched your search

+13 -1
View File
@@ -53,7 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const hashedPassword = await hashPassword(password);
await prisma.user.upsert({
const user = await prisma.user.upsert({
where: { email: userEmail },
update: {
username,
@@ -69,5 +69,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
});
// If user has been invitedTo a team, we accept the membership
if (user.invitedTo) {
await prisma.membership.update({
where: {
userId_teamId: { userId: user.id, teamId: user.invitedTo },
},
data: {
accepted: true,
},
});
}
res.status(201).json({ message: "Created user" });
}