Fix syntax errors preventing dev server from starting
This commit is contained in:
+18
-19
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user