ahora las opciones de grupos corresponden a las que existen en vez de
ser hardcode
This commit is contained in:
@@ -11,8 +11,9 @@ public class GruposController : ControllerBase
|
|||||||
[HttpGet("api/admin/grupos")]
|
[HttpGet("api/admin/grupos")]
|
||||||
public IActionResult ObtenerGrupos([FromHeader(Name = "Auth")] string Auth)
|
public IActionResult ObtenerGrupos([FromHeader(Name = "Auth")] string Auth)
|
||||||
{
|
{
|
||||||
var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 18);
|
var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 18) || RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||||
if (ret == false) return BadRequest(new { message = "No tiene permiso para Gestionar grupos" });
|
if (ret == false) return BadRequest(new { message = "No tiene permiso para ver todos los grupos" });
|
||||||
|
|
||||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por el token que enviaste" });
|
if (cli == null) return BadRequest(new { message = "No hay un cliente por el token que enviaste" });
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,39 @@
|
|||||||
let grupo:string = $state("");
|
let grupo:string = $state("");
|
||||||
let SelCliente: Cliente = $state(null);
|
let SelCliente: Cliente = $state(null);
|
||||||
|
|
||||||
|
let gruposopt: GrupoDto[] = $state([]);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
cargaUsuarios();
|
cargaUsuarios();
|
||||||
|
ObtenerGrupos();
|
||||||
});
|
});
|
||||||
async function cargaUsuarios(){
|
|
||||||
try{
|
async function ObtenerGrupos() {
|
||||||
const response = await fetch($urlG+"/api/admin/clientes", {
|
try {
|
||||||
|
const ret = await fetch($urlG + "/api/admin/grupos", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": String(token),
|
Auth: token || "",
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
if (!ret.ok) {
|
||||||
|
modaldata = "Fallo Al intentar hacer la request";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gruposopt = await ret.json();
|
||||||
|
} catch {
|
||||||
|
modaldata = "Fallo Al intentar hacer la request";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cargaUsuarios() {
|
||||||
|
try {
|
||||||
|
const response = await fetch($urlG + "/api/admin/clientes", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Auth: String(token),
|
||||||
|
},
|
||||||
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let data: Cliente[] = await response.json();
|
let data: Cliente[] = await response.json();
|
||||||
Clientes = data;
|
Clientes = data;
|
||||||
@@ -38,7 +60,6 @@
|
|||||||
} catch {
|
} catch {
|
||||||
modaldata = "fallo al intentar obtener la lista de clientes";
|
modaldata = "fallo al intentar obtener la lista de clientes";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
async function cargaGrupos(cli: Cliente){
|
async function cargaGrupos(cli: Cliente){
|
||||||
try {
|
try {
|
||||||
@@ -284,21 +305,31 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
{#if showAddmenu}
|
{#if showAddmenu}
|
||||||
<div in:fade>
|
<div in:fade>
|
||||||
<BarraHorizontalConTexto text="Añadir Grupos al Usuario"/>
|
<BarraHorizontalConTexto text="Añadir Grupos al Usuario" />
|
||||||
<form class="card card-body" onsubmit={(e) => añadirGrupo(e,SelCliente, grupo)}>
|
<form
|
||||||
<div class="mb-3">
|
class="card card-body"
|
||||||
<label for="userRole" class="form-label">Seleccionar Grupo</label>
|
onsubmit={(e) => añadirGrupo(e, SelCliente, grupo)}
|
||||||
<select id="userRole" class="form-select" bind:value={grupo}>
|
>
|
||||||
<option value="Propietario">Propietario</option>
|
<div class="mb-3">
|
||||||
<option value="Inquilino">Inquilino</option>
|
<label for="userRole" class="form-label"
|
||||||
<option value="Admin">Admin</option>
|
>Seleccionar Grupo</label
|
||||||
<option value="Informes">Informes</option>
|
>
|
||||||
</select>
|
<select
|
||||||
</div>
|
id="userRole"
|
||||||
<button class="btn btn-primary" type="submit">Añadir</button>
|
class="form-select"
|
||||||
</form>
|
bind:value={grupo}
|
||||||
</div>
|
>
|
||||||
|
{#each gruposopt as g}
|
||||||
|
<option value={g.nombre}>{g.nombre}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary" type="submit"
|
||||||
|
>Añadir</button
|
||||||
|
>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user