feat: implement character changes page with new and modified character listings
All checks were successful
Build Docker Image / build (push) Successful in 1m23s

This commit is contained in:
2026-03-03 19:58:02 +01:00
parent 085dae6765
commit 6402c378dd
4 changed files with 246 additions and 25 deletions

View File

@@ -0,0 +1,88 @@
import { db } from '$lib/server/db';
import { character, characterScrapeValidation } from '$lib/server/db/schema';
export async function load() {
// Get all characters from both tables
const currentCharacters = await db.select().from(character);
const scrapedCharacters = await db.select().from(characterScrapeValidation);
// Create a map for quick lookup
const currentCharMap = new Map(currentCharacters.map(c => [c.id, c]));
// Compare and categorize changes
const changes: {
type: 'new' | 'modified';
id: string;
scraped: (typeof scrapedCharacters)[0];
current?: (typeof currentCharacters)[0];
differences?: Record<string, { current: any; scraped: any }>;
}[] = [];
for (const scraped of scrapedCharacters) {
const current = currentCharMap.get(scraped.id);
if (!current) {
// New character
changes.push({
type: 'new',
id: scraped.id,
scraped
});
} else {
// Check if different
const differences: Record<string, { current: any; scraped: any }> = {};
const fieldsToCompare = [
'name',
'gender',
'age',
'affiliations',
'devilFruitId',
'hakiObservation',
'hakiArmament',
'hakiConqueror',
'bounty',
'height',
'origin',
'firstAppearance',
'pictureUrl',
'epithets',
'status',
'arcId',
'url'
];
for (const field of fieldsToCompare) {
const currentValue = current[field as keyof typeof current];
const scrapedValue = scraped[field as keyof typeof scraped];
// Deep comparison for JSON fields
if (JSON.stringify(currentValue) !== JSON.stringify(scrapedValue)) {
differences[field] = {
current: currentValue,
scraped: scrapedValue
};
}
}
if (Object.keys(differences).length > 0) {
changes.push({
type: 'modified',
id: scraped.id,
scraped,
current,
differences
});
}
}
}
return {
changes: changes.sort((a, b) => {
// Show 'new' first, then 'modified'
if (a.type !== b.type) {
return a.type === 'new' ? -1 : 1;
}
return a.id.localeCompare(b.id);
})
};
}