Skip to content

Commit

Permalink
Add additional join logic for admins
Browse files Browse the repository at this point in the history
Signed-off-by: Phrosfire <65364337+Phrosfire@users.noreply.github.com>
  • Loading branch information
Phrosfire authored Feb 25, 2025
1 parent 22bf950 commit 1176426
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/src/server/api/routers/clan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,35 @@ export const clanRouter = createTRPCRouter({
}
return errorResponse(`Failed to initiate ${groupLabel} battle`);
}),
instantJoinAndLead: protectedProcedure
.input(z.object({ clanId: z.string() }))
.output(baseServerResponse)
.mutation(async ({ ctx, input }) => {
const [user, fetchedClan] = await Promise.all([
fetchUser(ctx.drizzle, ctx.userId),
fetchClan(ctx.drizzle, input.clanId),
]);
if (!fetchedClan) return errorResponse("Faction not found");
if (!user) return errorResponse("User not found");
if (!canEditClans(user.role)) return errorResponse("Permission denied");
if (user.clanId) return errorResponse("Already in a faction");

await ctx.drizzle.transaction(async (tx) => {
await tx
.update(userData)
.set({ clanId: fetchedClan.id, villageId: fetchedClan.village?.id })
.where(eq(userData.userId, user.userId));
await tx
.update(clan)
.set({ leaderId: user.userId })
.where(eq(clan.id, fetchedClan.id));
});

return {
success: true,
message: `You have instantly joined and taken leadership of ${fetchedClan.name}`,
};
}),
});

/**
Expand Down

0 comments on commit 1176426

Please sign in to comment.