Refactor code structure for improved readability and maintainability
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 53s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 53s
This commit is contained in:
38
backend/scripts/checkDrawingData.js
Normal file
38
backend/scripts/checkDrawingData.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import PredefinedActivity from '../models/PredefinedActivity.js';
|
||||
import sequelize from '../database.js';
|
||||
|
||||
async function check() {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
const rows = await PredefinedActivity.findAll({ attributes: ['id', 'name', 'drawingData'] });
|
||||
const invalid = [];
|
||||
for (const r of rows) {
|
||||
const id = r.id;
|
||||
const name = r.name;
|
||||
const raw = r.drawingData;
|
||||
if (raw == null) continue;
|
||||
if (typeof raw !== 'string') {
|
||||
invalid.push({ id, name, reason: 'not-string', raw: String(raw).slice(0, 200) });
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
JSON.parse(raw);
|
||||
} catch (e) {
|
||||
// If raw looks like an object literal without quotes, consider invalid
|
||||
invalid.push({ id, name, reason: 'invalid-json', error: e.message, raw: raw.slice(0, 200) });
|
||||
}
|
||||
}
|
||||
if (invalid.length === 0) {
|
||||
console.log('No invalid drawingData found.');
|
||||
} else {
|
||||
console.log('Invalid drawingData rows:');
|
||||
invalid.forEach(i => console.log(JSON.stringify(i)));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Script error', err);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
check();
|
||||
Reference in New Issue
Block a user