feat(config): agrega opcion para eliminar empleados
Some checks failed
CI / lint-and-test (3.11) (push) Has been cancelled
CI / lint-and-test (3.13) (push) Has been cancelled

- Backend: nuevo endpoint DELETE /employees/<id> que desactiva (soft-delete).
  No permite eliminar cuentas de dueno.
- Frontend: boton Eliminar en la tabla de empleados con confirmacion.
- Exponer deleteEmployee en el modulo Config.

Tests: 35 passed
This commit is contained in:
2026-06-30 17:28:48 +00:00
parent 76dfa2adff
commit 8b378c3476
2 changed files with 49 additions and 2 deletions

View File

@@ -298,7 +298,10 @@ const Config = (() => {
+ '<td>' + escHtml(emp.branch_name || 'Todas') + '</td>'
+ '<td>' + statusBadge + '</td>'
+ '<td>' + (emp.max_discount_pct || 0) + '%</td>'
+ '<td><button class="btn btn--ghost btn--sm" onclick="Config.editEmployee(' + emp.id + ')">Editar</button></td>'
+ '<td>'
+ '<button class="btn btn--ghost btn--sm" onclick="Config.editEmployee(' + emp.id + ')">Editar</button>'
+ (emp.role !== 'owner' ? ' <button class="btn btn--danger btn--sm" onclick="Config.deleteEmployee(' + emp.id + ', \'' + escHtml(emp.name).replace(/\\/g, '\\\\').replace(/'/g, "\\'") + '\')">Eliminar</button>' : '')
+ '</td>'
+ '</tr>';
});
@@ -362,6 +365,21 @@ const Config = (() => {
return el ? el.value.trim() : '';
}
async function deleteEmployee(empId, name) {
if (!confirm('¿Eliminar al empleado "' + name + '"? Esta accion lo desactiva.')) return;
try {
var res = await fetch(API + '/employees/' + empId, { method: 'DELETE', headers: headers() });
if (!res.ok) {
var err = await res.json().catch(function() { return { error: 'Error ' + res.status }; });
throw new Error(err.error || 'Error al eliminar');
}
toast('Empleado eliminado', 'ok');
loadEmployees();
} catch (e) {
toast(e.message, 'error');
}
}
async function editEmployee(empId) {
if (!checkAuth()) return;
// Find the employee in the loaded data by re-fetching
@@ -1028,7 +1046,7 @@ const Config = (() => {
return {
init, setTheme, selectThemeOption, loadAllowedBrands, saveAllowedBrands,
loadBranches, loadEmployees, saveBranch, saveEmployee, editEmployee,
loadBranches, loadEmployees, saveBranch, saveEmployee, editEmployee, deleteEmployee,
loadBusiness, saveBusiness, saveTaxParams, saveAll,
loadCurrency, saveCurrency,
loadVehicleCompatSource, saveVehicleCompatSource,