Skip to content

Commit

Permalink
fix: JOIN-34406 handle duplication slug error during event type update (
Browse files Browse the repository at this point in the history
#58)

* fix: JOIN-34406 handle duplication slug error during event type update

* fix: JOIN-34406 handle duplication slug error during event type update
  • Loading branch information
dmkav committed Aug 10, 2023
1 parent 7923010 commit 9901c51
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/trpc/server/routers/viewer/eventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,13 +697,26 @@ export const eventTypesRouter = router({
}
}

const eventType = await ctx.prisma.eventType.update({
where: { id },
data,
});
let eventType;
try {
eventType = await ctx.prisma.eventType.update({
where: { id },
data,
});
} catch (error) {
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
throw new TRPCError({
code: "BAD_REQUEST",
message: "This url slug has been already used",
});
}

throw error;
}

const res = ctx.res as NextApiResponse;
if (typeof res?.revalidate !== "undefined") {
await res?.revalidate(`/${ctx.user.username}/${eventType.slug}`);
await res?.revalidate(`/${ctx.user.username}/${eventType?.slug}`);
}
return { eventType };
}),
Expand Down

0 comments on commit 9901c51

Please sign in to comment.