feat: enhance character status extraction and update schema for nullable status
All checks were successful
Build Docker Image / build (push) Successful in 1m22s

This commit is contained in:
2026-03-03 23:26:53 +01:00
parent 70de84f3ab
commit b5816e6c28
4 changed files with 165 additions and 27 deletions

View File

@@ -1,5 +1,64 @@
import { db } from '$lib/server/db';
import { character, characterScrapeValidation } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
async function upsertCharacterFromScrapeValidation(characterId: string): Promise<boolean> {
const [scraped] = await db
.select()
.from(characterScrapeValidation)
.where(eq(characterScrapeValidation.id, characterId));
if (!scraped) {
return false;
}
await db
.insert(character)
.values({
id: scraped.id,
name: scraped.name,
gender: scraped.gender,
age: scraped.age,
affiliations: scraped.affiliations,
devilFruitId: scraped.devilFruitId,
hakiObservation: scraped.hakiObservation,
hakiArmament: scraped.hakiArmament,
hakiConqueror: scraped.hakiConqueror,
bounty: scraped.bounty,
height: scraped.height,
origin: scraped.origin,
firstAppearance: scraped.firstAppearance,
pictureUrl: scraped.pictureUrl,
epithets: scraped.epithets,
status: scraped.status,
arcId: scraped.arcId,
url: scraped.url
})
.onConflictDoUpdate({
target: character.id,
set: {
name: scraped.name,
gender: scraped.gender,
age: scraped.age,
affiliations: scraped.affiliations,
devilFruitId: scraped.devilFruitId,
hakiObservation: scraped.hakiObservation,
hakiArmament: scraped.hakiArmament,
hakiConqueror: scraped.hakiConqueror,
bounty: scraped.bounty,
height: scraped.height,
origin: scraped.origin,
firstAppearance: scraped.firstAppearance,
pictureUrl: scraped.pictureUrl,
epithets: scraped.epithets,
status: scraped.status,
arcId: scraped.arcId,
url: scraped.url
}
});
return true;
}
export async function load() {
// Get all characters from both tables
@@ -86,3 +145,37 @@ export async function load() {
})
};
}
export const actions = {
acceptOne: async ({ request }) => {
const formData = await request.formData();
const characterId = formData.get('characterId');
if (!characterId || typeof characterId !== 'string') {
return { success: false, message: 'characterId is required' };
}
const applied = await upsertCharacterFromScrapeValidation(characterId);
return {
success: applied,
message: applied ? 'Character applied successfully' : 'Character not found in scrape validation table'
};
},
acceptAll: async () => {
const scrapedCharacters = await db.select().from(characterScrapeValidation);
let appliedCount = 0;
for (const scraped of scrapedCharacters) {
const applied = await upsertCharacterFromScrapeValidation(scraped.id);
if (applied) {
appliedCount++;
}
}
return {
success: true,
appliedCount
};
}
};