Agregar tab de pendientes, categoria procedimiento y fecha/hora programada
This commit is contained in:
@@ -16,6 +16,7 @@ import { initDb,
|
||||
getAllAtb, createAtb, updateAtb, deleteAtb,
|
||||
getAllIndicaciones, createIndicacion, updateIndicacion, deleteIndicacion,
|
||||
getAllMovimientosIndicaciones, createMovimientoIndicacion,
|
||||
getAllPendientes, createPendiente, updatePendiente, deletePendiente,
|
||||
getValue, setValue
|
||||
} from './db-mongodb.js';
|
||||
|
||||
@@ -63,6 +64,7 @@ app.get('/api/state', async (req, res) => {
|
||||
atb: await getAllAtb(),
|
||||
indicaciones: await getAllIndicaciones(),
|
||||
movimientosIndicaciones: await getAllMovimientosIndicaciones(),
|
||||
pendientes: await getAllPendientes(),
|
||||
usuarios: usuariosList.map(({ passwordHash, ...u }) => u),
|
||||
vistaActual: 'dashboard',
|
||||
currentInternacionId: null
|
||||
@@ -656,6 +658,43 @@ app.post('/api/movimientos-indicaciones', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ========== PENDIENTES ==========
|
||||
app.get('/api/pendientes', async (req, res) => {
|
||||
try {
|
||||
res.json(await getAllPendientes());
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Error al obtener pendientes' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/pendientes', async (req, res) => {
|
||||
try {
|
||||
const pendiente = { ...req.body, id: req.body.id || generateUUID() };
|
||||
await createPendiente(pendiente);
|
||||
res.json(pendiente);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Error al crear pendiente' });
|
||||
}
|
||||
});
|
||||
|
||||
app.put('/api/pendientes/:id', async (req, res) => {
|
||||
try {
|
||||
await updatePendiente(req.params.id, req.body);
|
||||
res.json({ ok: true });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Error al actualizar pendiente' });
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/pendientes/:id', async (req, res) => {
|
||||
try {
|
||||
await deletePendiente(req.params.id);
|
||||
res.json({ ok: true });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Error al eliminar pendiente' });
|
||||
}
|
||||
});
|
||||
|
||||
// ========== AUTH ==========
|
||||
app.post('/api/auth/login', async (req, res) => {
|
||||
try {
|
||||
|
||||
@@ -64,6 +64,7 @@ const memStore = {
|
||||
atb: [],
|
||||
indicaciones: [],
|
||||
movimientos_indicaciones: [],
|
||||
pendientes: [],
|
||||
kv: {}
|
||||
};
|
||||
|
||||
@@ -935,6 +936,42 @@ export async function createMovimientoIndicacion(mov) {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== PENDIENTES ==========
|
||||
export async function getAllPendientes() {
|
||||
if (db) {
|
||||
const pendientes = await db.collection('pendientes').find().toArray();
|
||||
return cleanDocs(pendientes);
|
||||
}
|
||||
return [...memStore.pendientes];
|
||||
}
|
||||
|
||||
export async function createPendiente(pendiente) {
|
||||
if (db) {
|
||||
await db.collection('pendientes').insertOne(pendiente);
|
||||
} else {
|
||||
memStore.pendientes.push(pendiente);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updatePendiente(id, datos) {
|
||||
if (db) {
|
||||
await db.collection('pendientes').updateOne({ id }, { $set: datos });
|
||||
} else {
|
||||
const idx = memStore.pendientes.findIndex(p => p.id === id);
|
||||
if (idx !== -1) {
|
||||
memStore.pendientes[idx] = { ...memStore.pendientes[idx], ...datos };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePendiente(id) {
|
||||
if (db) {
|
||||
await db.collection('pendientes').deleteOne({ id });
|
||||
} else {
|
||||
memStore.pendientes = memStore.pendientes.filter(p => p.id !== id);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== KV STORE ==========
|
||||
export async function getValue(key) {
|
||||
if (db) {
|
||||
|
||||
Reference in New Issue
Block a user