added ranking
This commit is contained in:
@@ -8,8 +8,6 @@ import {
|
||||
Get,
|
||||
Query,
|
||||
Delete,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
NotFoundException,
|
||||
Post,
|
||||
Res,
|
||||
@@ -19,7 +17,6 @@ import {
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
import type { Response } from 'express';
|
||||
|
||||
@@ -360,6 +357,12 @@ export class EquipoController {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('ranking')
|
||||
async ranking() {
|
||||
return this.equipoService.ranking();
|
||||
}
|
||||
}
|
||||
|
||||
let escritorio = ['ESCRITORIO PC', 'ESCRITORIO MAC OS ', 'ESCRITORIO LINUX'];
|
||||
|
||||
@@ -970,6 +970,42 @@ export class EquipoService {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async ranking() {
|
||||
const equipos = await this.equipoRepository.find({
|
||||
relations: ['mov', 'mov.user'],
|
||||
});
|
||||
|
||||
const conteo = new Map<
|
||||
number,
|
||||
{ id_usuario: number; nombre: string; total: number }
|
||||
>();
|
||||
|
||||
for (const equipo of equipos) {
|
||||
if (!equipo.mov || equipo.mov.length === 0) continue;
|
||||
|
||||
const ultimoMov = equipo.mov.sort(
|
||||
(a, b) =>
|
||||
new Date(b.fechaMovimiento).getTime() -
|
||||
new Date(a.fechaMovimiento).getTime(),
|
||||
)[0];
|
||||
|
||||
const user = ultimoMov.user;
|
||||
if (!user) continue;
|
||||
|
||||
if (!conteo.has(user.id_usuario)) {
|
||||
conteo.set(user.id_usuario, {
|
||||
id_usuario: user.id_usuario,
|
||||
nombre: user.nombre,
|
||||
total: 0,
|
||||
});
|
||||
}
|
||||
|
||||
conteo.get(user.id_usuario)!.total++;
|
||||
}
|
||||
|
||||
return Array.from(conteo.values()).sort((a, b) => b.total - a.total);
|
||||
}
|
||||
}
|
||||
|
||||
let estado_excluidos = ['DE BAJA'];
|
||||
|
||||
@@ -49,7 +49,7 @@ export class MovimientoService {
|
||||
}
|
||||
|
||||
const vistos = new Set<string>();
|
||||
const unicos: Movimiento[] = []; // <-- FIX
|
||||
const unicos: Movimiento[] = [];
|
||||
|
||||
for (const mov of movimientos) {
|
||||
const inventario = mov.equipo?.inventario;
|
||||
|
||||
Reference in New Issue
Block a user