Fix syntax errors preventing dev server from starting

This commit is contained in:
2026-08-09 20:23:28 +00:00
parent 4ae43e713a
commit de3627b5d4
3 changed files with 58 additions and 19 deletions
+18 -19
View File
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'url';
import bcrypt from 'bcryptjs';
import { existsSync, mkdirSync } from 'fs';
const currentDir = typeof currentDir !== 'undefined' ? currentDir : dirname(fileURLToPath(import.meta.url));
const currentDir = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url));
const DB_PATH = currentDir + '/data/hospital.db';
// Ensure data directory exists
@@ -83,24 +83,6 @@ export function initDb() {
internacionId TEXT,
sector TEXT DEFAULT 'En Área'
);
try {
db.prepare("ALTER TABLE camas ADD COLUMN sector TEXT DEFAULT 'En Área'").run();
} catch(e) {}
try {
// Initialize existing beds with their sector
const rows = db.prepare('SELECT id, numero FROM camas WHERE sector IS NULL OR sector = "En Área"').all();
for (const row of rows) {
if (!row.numero) continue;
const salaStr = String(row.numero).trim().split('-')[0].trim();
const salaNum = parseInt(salaStr, 10);
let s = 'En Área';
if (!isNaN(salaNum)) {
if (salaNum >= 300 && salaNum < 400 && salaNum % 2 !== 0) s = 'Fuera de Área';
else if (salaNum >= 400 && salaNum < 500) s = 'Fuera de Área';
}
db.prepare('UPDATE camas SET sector = ? WHERE id = ?').run(s, row.id);
}
} catch(e) {}
CREATE TABLE IF NOT EXISTS internaciones (
id TEXT PRIMARY KEY,
@@ -267,6 +249,23 @@ export function initDb() {
try { db.exec('ALTER TABLE camas ADD COLUMN areaId TEXT;'); } catch (_) {}
try { db.exec('ALTER TABLE internaciones ADD COLUMN areaId TEXT;'); } catch (_) {}
try { db.exec("ALTER TABLE camas ADD COLUMN sector TEXT DEFAULT 'En Área'"); } catch (_) {}
try {
// Initialize existing beds with their sector
const rows = db.prepare('SELECT id, numero FROM camas WHERE sector IS NULL OR sector = "En Área"').all();
for (const row of rows) {
if (!row.numero) continue;
const salaStr = String(row.numero).trim().split('-')[0].trim();
const salaNum = parseInt(salaStr, 10);
let s = 'En Área';
if (!isNaN(salaNum)) {
if (salaNum >= 300 && salaNum < 400 && salaNum % 2 !== 0) s = 'Fuera de Área';
else if (salaNum >= 400 && salaNum < 500) s = 'Fuera de Área';
}
db.prepare('UPDATE camas SET sector = ? WHERE id = ?').run(s, row.id);
}
} catch(e) {}
// Seed default 4 grupos if empty
try {
const defaultGrupos = [