Skip to content

Commit

Permalink
Update onboard-partner.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Nov 20, 2024
1 parent b1f27d9 commit 9270fcf
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions apps/web/lib/actions/partners/onboard-partner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,45 @@ export const onboardPartnerAction = authUserActionClient
userInfo: dotsUserInfo,
});

const partnerExists = await prisma.partner.findUnique({
where: {
dotsUserId: dotsUser.id,
},
});

if (partnerExists) {
throw new Error("This phone number is already in use.");
}

const partnerId = createId({ prefix: "pn_" });

try {
await prisma.partner.create({
const imageUrl = await storage
.upload(`partners/${partnerId}/image_${nanoid(7)}`, image)
.then(({ url }) => url);

const [partner, _] = await Promise.all([
prisma.partner.create({
data: {
id: partnerId,
name,
country,
bio: description,
dotsUserId: dotsUser.id,
image: imageUrl,
users: {
create: {
userId: user.id,
role: "owner",
},
},
},
});
} catch (error) {
if (error.code === "P2002") {
throw new Error("This phone number is already in use.");
}

throw new Error(error.message);
}

const imageUrl = await storage
.upload(`partners/${partnerId}/image_${nanoid(7)}`, image)
.then(({ url }) => url);

await Promise.all([
prisma.partner.update({
where: {
id: partnerId,
},
data: {
image: imageUrl,
},
}),

sendVerificationToken({
dotsUserId: dotsUser.id,
}),
]);

return {
partnerId,
partnerId: partner.id,
};
});

0 comments on commit 9270fcf

Please sign in to comment.