feat: refactor daily character logic to improve win count retrieval and streamline character selection
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { character, devilFruit, arc, user, config, characterHistory } from '$lib/server/db/schema';
|
||||
import { character, devilFruit, arc, user } from '$lib/server/db/schema';
|
||||
import { getOrCreateTodayCharacter, getTodayCharacterWinsCount } from '$lib/server/daily-character';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getDailyCharacterId } from '$lib/server/dailyCharacter';
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
const [characters, devilFruits, arcs, users, configEntries, history] = await Promise.all([
|
||||
const [characters, devilFruits, arcs, users] = await Promise.all([
|
||||
db.select().from(character),
|
||||
db.select().from(devilFruit),
|
||||
db.select().from(arc),
|
||||
db.select().from(user),
|
||||
db.select().from(config),
|
||||
db.select().from(characterHistory)
|
||||
db.select().from(user)
|
||||
]);
|
||||
|
||||
const dailyCharacterId = await getDailyCharacterId();
|
||||
// Return count of wins for the daily character , count is stored in won field of characterHistory
|
||||
const dailyCharacterWins = history.filter((h) => h.characterId === dailyCharacterId && h.won).length;
|
||||
// Get today's daily character and count wins
|
||||
const todayCharacter = await getOrCreateTodayCharacter();
|
||||
|
||||
let dailyCharacterWins = 0;
|
||||
if (todayCharacter) {
|
||||
dailyCharacterWins = await getTodayCharacterWinsCount(todayCharacter.id);
|
||||
}
|
||||
|
||||
return {
|
||||
stats: {
|
||||
|
||||
Reference in New Issue
Block a user