validate prestige

This commit is contained in:
Face 2025-06-27 21:31:39 +03:00
parent 8a8c141fbe
commit a227055c1e

View file

@ -34,6 +34,11 @@ export const POST: RequestHandler = async ({ request, locals }) => {
throw error(400, 'Maximum prestige level reached');
}
const currentCashBalance = Number(userData.baseCurrencyBalance);
if (currentCashBalance < prestigeCost) {
throw error(400, `Insufficient cash funds for prestige. Need ${formatValue(prestigeCost)} cash, have ${formatValue(currentCashBalance)} cash. Coin holdings cannot be used for prestige costs.`);
}
const holdings = await tx
.select({
coinId: userPortfolio.coinId,
@ -72,11 +77,6 @@ export const POST: RequestHandler = async ({ request, locals }) => {
.where(eq(userPortfolio.userId, userId));
}
const currentBalance = Number(userData.baseCurrencyBalance) + totalSaleValue;
if (currentBalance < prestigeCost) {
throw error(400, `Insufficient funds. Need ${formatValue(prestigeCost)}, have ${formatValue(currentBalance)}`);
}
await tx
.update(user)
.set({