follow: authedProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const userId = ctx.session.user?.id;
if (!userId) throw new TRPCError({ code: 'UNAUTHORIZED' });
const user = await ctx.prisma.user.findUniqueOrThrow({ where: { id: input.id } });
const userFollow = await ctx.prisma.userFollow.upsert({
where: { followerUserId_followTargetUserId: { followerUserId: userId, followTargetUserId: user.id } },
create: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
update: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
});
return {
userFollow,
};
}),
follow: authedProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const userId = ctx.session.user?.id;
if (!userId) throw new TRPCError({ code: 'UNAUTHORIZED' });
const user = await ctx.prisma.user.findUniqueOrThrow({ where: { id: input.id } });
const userFollow = await ctx.prisma.userFollow.upsert({
where: { followerUserId_followTargetUserId: { followerUserId: userId, followTargetUserId: user.id } },
create: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
update: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
});
return {
userFollow,
};
}),