From 0cbabc8da4316a1ffd4635c75097ad3929a43af6 Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Wed, 13 Aug 2025 09:55:32 -0600 Subject: [PATCH] fix(auth): ensure data persistence and correct login - Corrected the client table rendering function to prevent UI breaking. - Fixed a critical issue where data was not persisting in the local environment by ensuring an absolute path for the database. - Implemented a temporary password reset mechanism to regain access and then removed it. - Ensured client data is re-fetched from the server after saving to maintain UI consistency. --- ap-pos/app.js | 15 ++++----------- ap-pos/print.js | 3 ++- ap-pos/server.js | 3 ++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ap-pos/app.js b/ap-pos/app.js index d495c5e..3a97c25 100644 --- a/ap-pos/app.js +++ b/ap-pos/app.js @@ -162,16 +162,8 @@ async function saveClient(clientData) { await save('clients', { client: clientToSave }); - if (isUpdate) { - const index = clients.findIndex(c => c.id === clientToSave.id); - if (index > -1) { - clients[index] = clientToSave; - } - } else { - if (!clients.some(c => c.id === clientToSave.id)) { - clients.push(clientToSave); - } - } + // Volver a cargar los clientes desde el servidor para asegurar consistencia + clients = await load(KEY_CLIENTS, []); renderClientsTable(); updateClientDatalist(); @@ -233,12 +225,13 @@ function renderTable() { const client = clients.find(c => c.id === mov.clienteId); const tr = document.createElement('tr'); const fechaCita = mov.fechaCita ? new Date(mov.fechaCita + 'T00:00:00').toLocaleDateString('es-MX') : ''; + const tipoServicio = mov.subtipo ? `${mov.tipo} (${mov.subtipo})` : mov.tipo; tr.innerHTML = ` ${mov.folio} ${new Date(mov.fechaISO).toLocaleDateString('es-MX')} ${fechaCita} ${mov.horaCita || ''} ${client ? client.nombre : 'Cliente Eliminado'} - ${mov.tipo} + ${tipoServicio} ${Number(mov.monto).toFixed(2)} `; diff --git a/ap-pos/print.js b/ap-pos/print.js index b0bd3e1..d5b8a1d 100644 --- a/ap-pos/print.js +++ b/ap-pos/print.js @@ -23,6 +23,7 @@ function templateTicket(mov, settings) { const dt = new Date(mov.fechaISO || Date.now()); const fechaLocal = dt.toLocaleString('es-MX', { dateStyle: 'medium', timeStyle: 'short' }); const montoFormateado = Number(mov.monto).toFixed(2); + const tipoServicio = mov.subtipo === 'Retoque' ? `Retoque de ${mov.tipo}` : mov.tipo; const lines = []; lines.push('
'); @@ -39,7 +40,7 @@ function templateTicket(mov, settings) { lines.push(`
Fecha:${esc(fechaLocal)}
`); lines.push('
'); - lines.push(`
${esc(mov.tipo)}
`); + lines.push(`
${esc(tipoServicio)}
`); if (mov.client) lines.push(`
Cliente: ${esc(mov.client.nombre)}
`); if (mov.concepto) lines.push(`
Concepto: ${esc(mov.concepto)}
`); if (mov.staff) lines.push(`
Te atendió: ${esc(mov.staff)}
`); diff --git a/ap-pos/server.js b/ap-pos/server.js index 3e42474..736296b 100644 --- a/ap-pos/server.js +++ b/ap-pos/server.js @@ -23,7 +23,8 @@ app.use(session({ })); // --- DATABASE INITIALIZATION --- -const dbPath = process.env.DB_PATH || './ap-pos.db'; +// Usar un path absoluto para asegurar que la DB siempre se cree en la carpeta del proyecto. +const dbPath = path.join(__dirname, 'ap-pos.db'); console.log(`Connecting to database at: ${dbPath}`); const db = new sqlite3.Database(dbPath, (err) => {