Füge Validierung für Geschenke in FalukantService hinzu und erstelle Skripte zur Reparatur ungültiger Werte in PromotionalGift

This commit is contained in:
Torsten Schulz (local)
2026-02-14 16:19:31 +01:00
parent be7db6ad96
commit 91637ba7a3
3 changed files with 110 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
import { sequelize } from '../utils/sequelize.js';
import PromotionalGift from '../models/falukant/type/promotional_gift.js';
import PromotionalGiftMood from '../models/falukant/predefine/promotional_gift_mood.js';
import PromotionalGiftCharacterTrait from '../models/falukant/predefine/promotional_gift_character_trait.js';
async function dump() {
try {
await sequelize.authenticate();
console.log('DB connected');
const gifts = await PromotionalGift.findAll({
include: [
{ model: PromotionalGiftMood, as: 'promotionalgiftmoods', attributes: ['moodId', 'suitability'], required: false },
{ model: PromotionalGiftCharacterTrait, as: 'characterTraits', attributes: ['traitId', 'suitability'], required: false }
]
});
console.log(`found ${gifts.length} gifts`);
for (const g of gifts) {
console.log('---');
console.log('id:', g.id, 'name:', g.name, 'raw value type:', typeof g.value, 'value:', g.value);
try {
const plain = g.get({ plain: true });
console.log('plain value:', JSON.stringify(plain));
} catch (e) {
console.log('could not stringify plain', e);
}
}
} catch (err) {
console.error('dump failed', err);
process.exit(2);
} finally {
await sequelize.close();
}
}
dump();

View File

@@ -0,0 +1,61 @@
import PromotionalGift from '../models/falukant/type/promotional_gift.js';
import { sequelize } from '../utils/sequelize.js';
// Mapping basierend auf initializeFalukantTypes.js
const seedValues = {
'Gold Coin': 100,
'Silk Scarf': 50,
'Exotic Perfume': 200,
'Crystal Pendant': 150,
'Leather Journal': 75,
'Fine Wine': 120,
'Artisan Chocolate': 40,
'Pearl Necklace': 300,
'Rare Painting': 500,
'Silver Watch': 250,
'Cat': 70,
'Dog': 150,
'Horse': 1000
};
async function repair() {
console.log('Repair promotional_gift values - starting');
try {
await sequelize.authenticate();
console.log('DB connection ok');
// Liste aller problematischen Einträge
const [rows] = await sequelize.query("SELECT id, name, value FROM falukant_type.promotional_gift WHERE value IS NULL OR value <= 0");
if (!rows.length) {
console.log('No invalid promotional_gift rows found. Nothing to do.');
return process.exit(0);
}
console.log(`Found ${rows.length} invalid promotional_gift rows:`);
for (const r of rows) console.log(` id=${r.id} name='${r.name}' value=${r.value}`);
// Update rows where we have a seed mapping
let updated = 0;
for (const r of rows) {
const seed = seedValues[r.name];
if (seed && Number(seed) > 0) {
await PromotionalGift.update({ value: seed }, { where: { id: r.id } });
console.log(` updated id=${r.id} name='${r.name}' -> value=${seed}`);
updated++;
} else {
console.warn(` no seed value for id=${r.id} name='${r.name}' - skipping`);
}
}
console.log(`Done. Updated ${updated} rows. Remaining invalid: `);
const [left] = await sequelize.query("SELECT id, name, value FROM falukant_type.promotional_gift WHERE value IS NULL OR value <= 0");
for (const l of left) console.log(` id=${l.id} name='${l.name}' value=${l.value}`);
console.log('If any remain, inspect and adjust manually.');
process.exit(0);
} catch (err) {
console.error('Repair failed:', err);
process.exit(2);
}
}
repair();