up
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* modules/turnero/api/save_prioridad.php
|
||||
* POST {id, nombre, color, orden_peso, activo} → actualizar prioridad existente
|
||||
* (Las prioridades no se crean ni eliminan vía API — se gestionan en la migración)
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
|
||||
requireTurnero();
|
||||
requireMethod('POST');
|
||||
|
||||
$input = inputJson();
|
||||
|
||||
$id = (int)($input['id'] ?? 0);
|
||||
$nombre = trim($input['nombre'] ?? '');
|
||||
$color = trim($input['color'] ?? '#6b7280');
|
||||
$ordenPeso = (int)($input['orden_peso'] ?? 1);
|
||||
$activo = (int)($input['activo'] ?? 1);
|
||||
|
||||
if (!$id) jsonError('ID requerido');
|
||||
if ($nombre === '') jsonError('El nombre es requerido');
|
||||
if ($ordenPeso < 1) jsonError('El orden debe ser mayor a 0');
|
||||
if (!preg_match('/^#[0-9a-f]{6}$/i', $color)) jsonError('Color hexadecimal inválido (formato: #RRGGBB)');
|
||||
|
||||
$stmt = db()->prepare(
|
||||
'UPDATE turnero_prioridades SET nombre=?, color=?, orden_peso=?, activo=? WHERE id=?'
|
||||
);
|
||||
$stmt->execute([$nombre, $color, $ordenPeso, $activo, $id]);
|
||||
|
||||
if ($stmt->rowCount() === 0) {
|
||||
jsonError('Prioridad no encontrada', 404);
|
||||
}
|
||||
|
||||
jsonOk(['id' => $id], 'Prioridad actualizada');
|
||||
Reference in New Issue
Block a user