-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjustment to clans/hideouts #406
base: main
Are you sure you want to change the base?
Changes from all commits
1176426
f9c61cf
33b6f53
ef66d13
5cdb3b5
5a23390
b2016e6
723c176
f3a6332
242f2d4
4b6e67f
2a13628
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,7 @@ export const ElementNames = [ | |
"Lava", | ||
"Explosion", | ||
"Light", | ||
"Boil", | ||
"None", | ||
] as const; | ||
export type ElementName = (typeof ElementNames)[number]; | ||
|
@@ -903,6 +904,8 @@ export const IMG_ELEMENT_DUST = | |
"https://utfs.io/f/Hzww9EQvYURJchNmlmSnxBpQqGNDcTHbLmYz8uXAl3oa54ti"; | ||
export const IMG_ELEMENT_LIGHTNING = | ||
"https://utfs.io/f/Hzww9EQvYURJ4DIVIclYIif5CL8BKvMsOh2ZnmS7yHt0jTD3"; | ||
export const IMG_ELEMENT_BOIL = | ||
"https://i.imgur.com/63KgdPB.png"; | ||
Phrosfire marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
export const IMG_BASIC_HEAL = | ||
"https://utfs.io/f/Hzww9EQvYURJnlXNSKmojJ0EqeDCvBrNmZaXVdY97gSpOWiA"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid using transactions on the database; they work with planetscale, but I've consistently experienced when we introduce transactions we also start seeing deadlocks popping up. As for this specific case, I think simply putting the two transactions into a |
||
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}`, | ||
}; | ||
}), | ||
Phrosfire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add to
assets/elements/
folder for future recoverability :)