1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/recuperaIdEntero.php"; |
5 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
6 | require_once __DIR__ . "/../lib/php/recuperaArray.php"; |
7 | require_once __DIR__ . "/../lib/php/validaCue.php"; |
8 | require_once __DIR__ . "/../lib/php/update.php"; |
9 | require_once __DIR__ . "/../lib/php/delete.php"; |
10 | require_once __DIR__ . "/../lib/php/insertBridges.php"; |
11 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
12 | require_once __DIR__ . "/Bd.php"; |
13 | require_once __DIR__ . "/TABLA_USUARIO.php"; |
14 | require_once __DIR__ . "/TABLA_ROL.php"; |
15 | require_once __DIR__ . "/TABLA_USU_ROL.php"; |
16 | |
17 | ejecutaServicio(function () { |
18 | |
19 | $usuId = recuperaIdEntero("id"); |
20 | $cue = recuperaTexto("cue"); |
21 | $rolIds = recuperaArray("rolIds"); |
22 | |
23 | $cue = validaCue($cue); |
24 | |
25 | $pdo = Bd::pdo(); |
26 | $pdo->beginTransaction(); |
27 | |
28 | update( |
29 | pdo: $pdo, |
30 | table: USUARIO, |
31 | set: [USU_CUE => $cue], |
32 | where: [USU_ID => $usuId] |
33 | ); |
34 | delete(pdo: $pdo, from: USU_ROL, where: [USU_ID => $usuId]); |
35 | insertBridges( |
36 | pdo: $pdo, |
37 | into: USU_ROL, |
38 | valuesDePadre: [USU_ID => $usuId], |
39 | valueDeHijos: [ROL_ID => $rolIds] |
40 | ); |
41 | |
42 | $pdo->commit(); |
43 | |
44 | devuelveJson([ |
45 | "id" => ["value" => $usuId], |
46 | "cue" => ["value" => $cue], |
47 | "rolIds" => ["value" => $rolIds], |
48 | ]); |
49 | }); |
50 | |