mirror of
https://github.com/marcogll/ap_pos.git
synced 2026-01-13 13:15:16 +00:00
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.
This commit is contained in:
@@ -162,16 +162,8 @@ async function saveClient(clientData) {
|
|||||||
|
|
||||||
await save('clients', { client: clientToSave });
|
await save('clients', { client: clientToSave });
|
||||||
|
|
||||||
if (isUpdate) {
|
// Volver a cargar los clientes desde el servidor para asegurar consistencia
|
||||||
const index = clients.findIndex(c => c.id === clientToSave.id);
|
clients = await load(KEY_CLIENTS, []);
|
||||||
if (index > -1) {
|
|
||||||
clients[index] = clientToSave;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!clients.some(c => c.id === clientToSave.id)) {
|
|
||||||
clients.push(clientToSave);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderClientsTable();
|
renderClientsTable();
|
||||||
updateClientDatalist();
|
updateClientDatalist();
|
||||||
@@ -233,12 +225,13 @@ function renderTable() {
|
|||||||
const client = clients.find(c => c.id === mov.clienteId);
|
const client = clients.find(c => c.id === mov.clienteId);
|
||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
const fechaCita = mov.fechaCita ? new Date(mov.fechaCita + 'T00:00:00').toLocaleDateString('es-MX') : '';
|
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 = `
|
tr.innerHTML = `
|
||||||
<td><a href="#" class="action-btn" data-id="${mov.id}" data-action="reprint">${mov.folio}</a></td>
|
<td><a href="#" class="action-btn" data-id="${mov.id}" data-action="reprint">${mov.folio}</a></td>
|
||||||
<td>${new Date(mov.fechaISO).toLocaleDateString('es-MX')}</td>
|
<td>${new Date(mov.fechaISO).toLocaleDateString('es-MX')}</td>
|
||||||
<td>${fechaCita} ${mov.horaCita || ''}</td>
|
<td>${fechaCita} ${mov.horaCita || ''}</td>
|
||||||
<td>${client ? client.nombre : 'Cliente Eliminado'}</td>
|
<td>${client ? client.nombre : 'Cliente Eliminado'}</td>
|
||||||
<td>${mov.tipo}</td>
|
<td>${tipoServicio}</td>
|
||||||
<td>${Number(mov.monto).toFixed(2)}</td>
|
<td>${Number(mov.monto).toFixed(2)}</td>
|
||||||
<td><button class="action-btn" data-id="${mov.id}" data-action="delete">Eliminar</button></td>
|
<td><button class="action-btn" data-id="${mov.id}" data-action="delete">Eliminar</button></td>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ function templateTicket(mov, settings) {
|
|||||||
const dt = new Date(mov.fechaISO || Date.now());
|
const dt = new Date(mov.fechaISO || Date.now());
|
||||||
const fechaLocal = dt.toLocaleString('es-MX', { dateStyle: 'medium', timeStyle: 'short' });
|
const fechaLocal = dt.toLocaleString('es-MX', { dateStyle: 'medium', timeStyle: 'short' });
|
||||||
const montoFormateado = Number(mov.monto).toFixed(2);
|
const montoFormateado = Number(mov.monto).toFixed(2);
|
||||||
|
const tipoServicio = mov.subtipo === 'Retoque' ? `Retoque de ${mov.tipo}` : mov.tipo;
|
||||||
|
|
||||||
const lines = [];
|
const lines = [];
|
||||||
lines.push('<div class="ticket">');
|
lines.push('<div class="ticket">');
|
||||||
@@ -39,7 +40,7 @@ function templateTicket(mov, settings) {
|
|||||||
lines.push(`<div class="t-row t-small"><span>Fecha:</span><span>${esc(fechaLocal)}</span></div>`);
|
lines.push(`<div class="t-row t-small"><span>Fecha:</span><span>${esc(fechaLocal)}</span></div>`);
|
||||||
|
|
||||||
lines.push('<div class="t-divider"></div>');
|
lines.push('<div class="t-divider"></div>');
|
||||||
lines.push(`<div><span class="t-bold">${esc(mov.tipo)}</span></div>`);
|
lines.push(`<div><span class="t-bold">${esc(tipoServicio)}</span></div>`);
|
||||||
if (mov.client) lines.push(`<div class="t-small">Cliente: ${esc(mov.client.nombre)}</div>`);
|
if (mov.client) lines.push(`<div class="t-small">Cliente: ${esc(mov.client.nombre)}</div>`);
|
||||||
if (mov.concepto) lines.push(`<div class="t-small">Concepto: ${esc(mov.concepto)}</div>`);
|
if (mov.concepto) lines.push(`<div class="t-small">Concepto: ${esc(mov.concepto)}</div>`);
|
||||||
if (mov.staff) lines.push(`<div class="t-small"><b>Te atendió:</b> ${esc(mov.staff)}</div>`);
|
if (mov.staff) lines.push(`<div class="t-small"><b>Te atendió:</b> ${esc(mov.staff)}</div>`);
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ app.use(session({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// --- DATABASE INITIALIZATION ---
|
// --- 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}`);
|
console.log(`Connecting to database at: ${dbPath}`);
|
||||||
|
|
||||||
const db = new sqlite3.Database(dbPath, (err) => {
|
const db = new sqlite3.Database(dbPath, (err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user