- Added character selection and history management using local storage. - Implemented hint system that unlocks based on the number of guesses. - Enhanced UI with animations for hint unlocks and special win conditions. - Created a server endpoint to record wins in the database.
34 lines
906 B
TypeScript
34 lines
906 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { db } from '$lib/server/db';
|
|
import { characterHistory } from '$lib/server/db/schema';
|
|
import { eq } from 'drizzle-orm';
|
|
import { sql } from 'drizzle-orm';
|
|
|
|
export async function POST({ request }) {
|
|
try {
|
|
const { characterId } = await request.json();
|
|
|
|
if (!characterId) {
|
|
return json({ error: 'Missing characterId' }, { status: 400 });
|
|
}
|
|
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
const todayDate = today.toISOString().split('T')[0];
|
|
|
|
// Increment the won counter for today's entry
|
|
await db
|
|
.update(characterHistory)
|
|
.set({
|
|
won: sql`${characterHistory.won} + 1`,
|
|
updatedAt: Date.now()
|
|
})
|
|
.where(eq(characterHistory.date, todayDate));
|
|
|
|
return json({ success: true });
|
|
} catch (error) {
|
|
console.error('Error recording win:', error);
|
|
return json({ error: 'Failed to record win' }, { status: 500 });
|
|
}
|
|
}
|