Database Migration: - Add MariaDB connection configuration and initialization (mariadb.js) - Create MariaDB schema update script (mariadb-schema-update.sql) - Add migration scripts for SQLite to MariaDB transition: * migrate-sqlite-to-mariadb.js: Main migration script * migrate-inventory-to-gear.js: Inventory schema migration - Remove SQLite-specific implementation files and databases Route Updates: - Update all route handlers to use MariaDB instead of SQLite - Migrate routes: playerRoutes, sessionRoutes, shopRoutes, bestiaryRoutes, rulesRoutes, rulesStagingRoutes, weaponsRoutes - Remove SQLite-specific route files (playerRoutes-sqlite.js, sessionRoutes-sqlite.js) - Update server.js to initialize MariaDB and register new weapon routes Backend Scripts: - Remove old SQLite migration scripts (migrate-to-sqlite.js, server-sqlite.js) - Delete obsolete database utility scripts from backup-scripts/ Frontend Updates: - Update logger utility for improved error handling and debugging - Enhance PlayerManagement component with better state management - Improve RequisitionShop component for MariaDB integration - Update DeathwatchRoller with performance improvements - Add login test suite (login.test.js) - Add XP progression utility (xpProgression.js) - Update dependencies in package.json and package-lock.json This migration improves: - Database scalability and performance - Transaction support for complex operations - Better data integrity and ACID compliance - Simplified deployment and backup procedures
27 lines
838 B
JavaScript
27 lines
838 B
JavaScript
const express = require('express')
|
|
const router = express.Router()
|
|
const { weaponsHelpers, logToFile } = require('../mariadb')
|
|
|
|
// Return weapons in a normalized shape
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const rows = await weaponsHelpers.getAll()
|
|
const parsed = rows.map(r => {
|
|
let stats = {}
|
|
try {
|
|
stats = typeof r.stats === 'string' ? JSON.parse(r.stats) : r.stats || {}
|
|
} catch (e) {
|
|
logToFile('Error parsing weapon stats for', r.name, e)
|
|
}
|
|
return { id: r.id, name: r.name, category: r.category, stats: stats, source: r.source }
|
|
})
|
|
res.json(parsed)
|
|
} catch (e) {
|
|
console.error('Failed to load weapons from MariaDB:', e)
|
|
logToFile('Error getting weapons:', e)
|
|
res.status(500).json({ error: 'Failed to get weapons' })
|
|
}
|
|
})
|
|
|
|
module.exports = router
|