lucas me pidio las lineas de codigo
This commit is contained in:
@@ -38,12 +38,15 @@ public class AdminController: ControllerBase
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo);
|
||||
if (ret) return BadRequest(new { message = $"El usuario ya pertenece al grupo {data.grupo}"});
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo);
|
||||
var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo, cli.Dni);
|
||||
|
||||
return ret2 ? Ok(new {message = "Se Añadio al Grupo"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
@@ -54,6 +57,10 @@ public class AdminController: ControllerBase
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
//una ward para que no me bloquee a mi mismo de tener acceso a admin
|
||||
@@ -74,7 +81,7 @@ public class AdminController: ControllerBase
|
||||
if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"});
|
||||
}
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo);
|
||||
var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo, cli.Dni);
|
||||
return ret2 ? Ok(new {message = $"Se elimino del Grupo: {data.grupo}"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace AlquilaFacil.Controllers;
|
||||
public class LogsController: ControllerBase {
|
||||
|
||||
[HttpGet("/api/Logs")]
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, long pag=1) {
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, int pag=1) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
@@ -49,4 +49,14 @@ public class LogsController: ControllerBase {
|
||||
}
|
||||
return Ok(ll);
|
||||
}
|
||||
|
||||
[HttpGet("/api/Logs/cantPag")]
|
||||
public IActionResult cantidadPaginas([FromHeader(Name = "Auth")] string Auth){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
int c = RepositorioLogs.Singleton.ObtenerCantidadPaginas();
|
||||
return Ok(c);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[HttpPost("/api/ventas/subirReciboPago")]
|
||||
public async Task<IActionResult> SubirRecibo([FromHeader(Name="Auth")]string Auth, [FromForm]IFormFile file, long idventa ) {
|
||||
public async Task<IActionResult> SubirRecibo([FromHeader(Name="Auth")]string Auth, IFormFile file, long idventa ) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
|
||||
@@ -447,10 +447,15 @@ public partial class AlquilaFacilContext : DbContext
|
||||
|
||||
modelBuilder.Entity<LogDetalle>(entity =>
|
||||
{
|
||||
entity.HasKey(e => new { e.Fecha, e.Dniusuario, e.NombreTabla, e.Columna }).HasName("PRIMARY");
|
||||
entity.HasKey(e => new { e.Id, e.Fecha, e.Dniusuario, e.NombreTabla, e.Columna }).HasName("PRIMARY");
|
||||
|
||||
entity.ToTable("LogDetalle");
|
||||
|
||||
entity.HasIndex(e => new { e.Fecha, e.Dniusuario }, "LogDetalle_ibfk_1");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Fecha)
|
||||
.HasColumnType("datetime")
|
||||
.HasColumnName("fecha");
|
||||
|
||||
@@ -17,5 +17,7 @@ public partial class LogDetalle
|
||||
|
||||
public string? ValorNuevo { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual Log Log { get; set; } = null!;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
import Informes from "./paginas/Informes.svelte";
|
||||
import CompraYVentas from "./paginas/CompraYVenta.svelte";
|
||||
import Ventas from "./paginas/Ventas.svelte";
|
||||
import VerLogs from "./paginas/VerLogs.svelte";
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
@@ -72,6 +73,11 @@
|
||||
<ProteRoute componente={Informes}/>
|
||||
</Route>
|
||||
|
||||
<!--Ver Logs-->
|
||||
<Route path="/accion/7">
|
||||
<ProteRoute componente={VerLogs}/>
|
||||
</Route>
|
||||
|
||||
<!--Administrar Propiedades Dadas de Baja-->
|
||||
<Route path="/accion/8">
|
||||
<ProteRoute componente={MisPropiedadesDeBaja}/>
|
||||
|
||||
63
Front/src/Componentes/ModalLogs.svelte
Normal file
63
Front/src/Componentes/ModalLogs.svelte
Normal file
@@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import type { LogDetalleDto, LogDto } from "../types";
|
||||
|
||||
let {onClose, log}: {onClose: ()=>boolean, log:LogDto} = $props();
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
|
||||
let detalles: LogDetalleDto[] = $state([]);
|
||||
async function obtenerDetalles() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs/detalle?fecha="+log.fecha+"&idusuario="+log.dniusuario, {
|
||||
method:"GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
detalles = data;
|
||||
return;
|
||||
}
|
||||
}catch{}
|
||||
}
|
||||
onMount(()=>{
|
||||
obtenerDetalles();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="modal fade show" tabindex="-1" role="dialog" style="display: block; background-color: rgba(0, 0, 0, 0.5);">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Detalles Log</h1>
|
||||
<button class="btn-close" onclick={onClose} aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-striped" style="table-layout: fixed; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="word-wrap: break-word;">Fecha</th>
|
||||
<th style="word-wrap: break-word;">Tabla</th>
|
||||
<th style="word-wrap: break-word;">Columna</th>
|
||||
<th style="word-wrap: break-word;">Valor Viejo</th>
|
||||
<th style="word-wrap: break-word;">Valor Nuevo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each detalles as d}
|
||||
<tr>
|
||||
<td style="word-wrap: break-word;">{d.fecha}</td>
|
||||
<td style="word-wrap: break-word;">{d.nombreTabla}</td>
|
||||
<td style="word-wrap: break-word;">{d.columna}</td>
|
||||
<td style="word-wrap: break-word;">{d.valorAnterior}</td>
|
||||
<td style="word-wrap: break-word;">{d.valorNuevo}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
|
||||
let {currentPag,
|
||||
cantpag,
|
||||
@@ -10,13 +9,6 @@
|
||||
cantpag: number,
|
||||
queryPag: (a:number) => void} = $props();
|
||||
|
||||
|
||||
const token = sessionStorage.getItem("token");
|
||||
|
||||
onMount(async () => {
|
||||
|
||||
});
|
||||
|
||||
let array = $derived.by(()=> Array.from({ length: cantpag }, (_, i) => i + 1));
|
||||
</script>
|
||||
|
||||
|
||||
109
Front/src/paginas/VerLogs.svelte
Normal file
109
Front/src/paginas/VerLogs.svelte
Normal file
@@ -0,0 +1,109 @@
|
||||
<script lang="ts">
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { LogDetalleDto, LogDto } from "../types";
|
||||
import { onMount } from "svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import ModalLogs from "../Componentes/ModalLogs.svelte";
|
||||
import PaginacionStepper from "../Componentes/PaginacionStepper.svelte";
|
||||
|
||||
let Logs: LogDto[] = $state([]);
|
||||
let pagina:number = $state(1);
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
let modaldata:string = $state("");
|
||||
let showmodal:boolean =$state(false);
|
||||
let ll:LogDto|any = $state({});
|
||||
let cantpag:number = $state(100);
|
||||
|
||||
onMount(()=>{
|
||||
obtenerLogs();
|
||||
obtenerPaginas();
|
||||
});
|
||||
|
||||
async function obtenerPaginas() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs/cantPag", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
cantpag = data;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "no se pudo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function obtenerLogs() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs?pag="+pagina, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
Logs = data;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "no se pudo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
function prepararModal(l: LogDto) {
|
||||
ll = l;
|
||||
showmodal = true;
|
||||
}
|
||||
function queryPag(a:number) {
|
||||
pagina = a;
|
||||
obtenerLogs();
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
|
||||
{/if}
|
||||
|
||||
{#if showmodal}
|
||||
<ModalLogs onClose={()=>!!(showmodal=!showmodal)} log={ll}/>
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid mt-2">
|
||||
<BarraHorizontalConTexto text={"Logs"}/>
|
||||
<table class="table table-responsive table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Fecha</th>
|
||||
<th>Id Usuario</th>
|
||||
<th>Accion</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Logs as l}
|
||||
<tr>
|
||||
<td>{l.fecha}</td>
|
||||
<td>{l.dniusuario}</td>
|
||||
<td>{l.accion}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary" onclick={()=>prepararModal(l)}>
|
||||
Ver
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<PaginacionStepper currentPag={pagina} {cantpag} {queryPag}/>
|
||||
</div>
|
||||
15
Front/src/types.d.ts
vendored
15
Front/src/types.d.ts
vendored
@@ -164,4 +164,19 @@ export type VentasDto = {
|
||||
nombreComprador:string,
|
||||
idComprador:number,
|
||||
estado:string,
|
||||
}
|
||||
|
||||
export type LogDto = {
|
||||
fecha:Date,
|
||||
dniusuario:number,
|
||||
accion:string
|
||||
}
|
||||
|
||||
export type LogDetalleDto = {
|
||||
fecha:Date,
|
||||
dniusuario:number,
|
||||
nombreTabla:string,
|
||||
columna:string,
|
||||
valorAnterior:string,
|
||||
valorNuevo:string
|
||||
}
|
||||
@@ -44,14 +44,21 @@ public class AuditoriaFacade {
|
||||
var valorNuevo = cambio.CurrentValues[propiedad]?.ToString();
|
||||
|
||||
if (_validadorDeCambios.ValidarCambio(valorAnterior??"", valorNuevo??"")) {
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -61,14 +68,21 @@ public class AuditoriaFacade {
|
||||
if (propiedad.Name == "Token") break;
|
||||
var valorNuevo = cambio.CurrentValues[propiedad]?.ToString();
|
||||
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = null,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = null,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -77,14 +91,21 @@ public class AuditoriaFacade {
|
||||
if (propiedad.Name == "Token") break;
|
||||
var valorAnterior = cambio.OriginalValues[propiedad]?.ToString();
|
||||
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = null
|
||||
});
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = null
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@ public class PersistenciaLog {
|
||||
private AlquilaFacilContext _context {get{return new AlquilaFacilContext();}}
|
||||
public void GuardarLog(Log log, IEnumerable<LogDetalle> detalles) {
|
||||
var con = _context;
|
||||
int j = 1;
|
||||
foreach (var i in log.LogDetalles) {
|
||||
i.Id = j;
|
||||
j++;
|
||||
}
|
||||
con.Logs.Add(log);
|
||||
con.LogDetalles.AddRange(detalles);
|
||||
//con.LogDetalles.AddRange(detalles);
|
||||
con.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,21 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
public class RepositorioLogs: RepositorioBase<RepositorioLogs> {
|
||||
public ICollection<LogDetalle> ObtenerDetallesLogs(DateTime fecha, long idusuario) {
|
||||
public int ObtenerCantidadPaginas() {
|
||||
var con = Context;
|
||||
float a = con.Logs.Count()/10f;
|
||||
int b = (int)a;
|
||||
if (b != a){
|
||||
b++;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public IOrderedEnumerable<LogDetalle> ObtenerDetallesLogs(DateTime fecha, long idusuario) {
|
||||
var con = Context;
|
||||
var d = con.Logs.Include(x=>x.LogDetalles)
|
||||
.FirstOrDefault(x => x.Fecha == fecha && x.Dniusuario == idusuario);
|
||||
return d.LogDetalles;
|
||||
return d.LogDetalles.OrderBy(x=>x.Id);
|
||||
}
|
||||
|
||||
public IQueryable<Log>? ObtenerLogsPaginado(int pag) {
|
||||
|
||||
@@ -129,7 +129,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool AñadirClienteAGrupo(string email, string grupo) {
|
||||
public bool AñadirClienteAGrupo(string email, string grupo, long dni) {
|
||||
var con = Context;
|
||||
|
||||
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||
@@ -140,11 +140,11 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
}
|
||||
|
||||
cli.Idgrupos.Add(gru);
|
||||
GenerarLog(con, cli.Dni, $"Añadir grupo: {gru.Nombre}");
|
||||
GenerarLog(con, dni, $"Añadir grupo: {gru.Nombre}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool EliminarClienteAGrupo(string email, string grupo) {
|
||||
public bool EliminarClienteAGrupo(string email, string grupo, long dniresponsable) {
|
||||
var con = Context;
|
||||
|
||||
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||
@@ -154,7 +154,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
return false;
|
||||
}
|
||||
cli.Idgrupos.Remove(gru);
|
||||
GenerarLog(con, cli.Dni, $"Eliminar de grupo: {gru.Nombre}");
|
||||
GenerarLog(con, dniresponsable, $"Eliminar de grupo: {gru.Nombre}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user