Füge Validierung für Geschenke in FalukantService hinzu und erstelle Skripte zur Reparatur ungültiger Werte in PromotionalGift
This commit is contained in:
@@ -3119,8 +3119,18 @@ class FalukantService extends BaseService {
|
||||
characterTitleOfNobility = reloadChar?.titleOfNobility ?? lowestTitleOfNobility?.id ?? 1;
|
||||
}
|
||||
|
||||
return Promise.all(gifts.map(async gift => {
|
||||
const value = typeof gift.value === 'number' ? gift.value : (gift.value ? Number(gift.value) : 0);
|
||||
// Filtere Gifts ohne gültigen 'value' (0 oder fehlend) — solche sollten in der DB korrigiert werden
|
||||
const validGifts = gifts.filter(g => Number(g.value) > 0);
|
||||
const skipped = gifts.length - validGifts.length;
|
||||
if (skipped > 0) {
|
||||
console.warn(`getGifts: skipped ${skipped} promotional gifts with invalid value`);
|
||||
for (const g of gifts) {
|
||||
if (!(Number(g.value) > 0)) console.warn(` skipped gift id=${g.id} name=${g.name} value=${g.value}`);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(validGifts.map(async gift => {
|
||||
const value = Number(gift.value);
|
||||
const cost = await this.getGiftCost(value, characterTitleOfNobility, lowestTitleOfNobility?.id ?? 1);
|
||||
return {
|
||||
id: gift.id,
|
||||
|
||||
37
backend/tools/dumpGiftsDebug.js
Normal file
37
backend/tools/dumpGiftsDebug.js
Normal 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();
|
||||
61
backend/tools/repairPromotionalGifts.js
Normal file
61
backend/tools/repairPromotionalGifts.js
Normal 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();
|
||||
Reference in New Issue
Block a user