feat: add daily fruit feature and related components
Build Docker Image / build (push) Successful in 2m8s
Build Docker Image / build (push) Successful in 2m8s
- Introduced a new daily fruit selection mechanism with associated database schema. - Created routes and components for displaying and interacting with daily fruit. - Implemented logic for tracking wins related to daily fruit and character guesses. - Added localization support for new daily fruit titles in English and French. - Enhanced the user experience with history tracking for guesses and wins. - Refactored existing character-related logic to accommodate new fruit functionality.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db';
|
||||
import { devilFruitHistory } from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { getDateKey } from '$lib/server/daily-fruit';
|
||||
|
||||
export async function POST({ request, locals }) {
|
||||
try {
|
||||
const { characterId, tryCount, triedCharacterIds } = await request.json();
|
||||
|
||||
if (!characterId) {
|
||||
return json({ error: 'Missing characterId' }, { status: 400 });
|
||||
}
|
||||
|
||||
const todayDate = getDateKey(new Date());
|
||||
|
||||
// Increment the won counter for today's devil fruit entry
|
||||
await db
|
||||
.update(devilFruitHistory)
|
||||
.set({
|
||||
won: sql`${devilFruitHistory.won} + 1`,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
.where(eq(devilFruitHistory.date, todayDate));
|
||||
|
||||
return json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error recording fruit win:', error);
|
||||
return json({ error: 'Failed to record win' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user