modified ranking
This commit is contained in:
@@ -358,10 +358,10 @@ export class EquipoController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('ranking')
|
||||
async ranking() {
|
||||
return this.equipoService.ranking();
|
||||
|
||||
@Get('ranking/:year')
|
||||
async ranking(@Param('year') year: string) {
|
||||
return this.equipoService.ranking(Number(year));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ export class EquipoService {
|
||||
private readonly laboratorioRepo: Repository<Laboratorio>,
|
||||
@InjectRepository(Proyecto)
|
||||
private readonly proyectoRepo: Repository<Proyecto>,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async deleteEquipo(inventario: string): Promise<{ message: string }> {
|
||||
const equipo = await this.equipoRepository.findOne({
|
||||
@@ -293,12 +293,12 @@ export class EquipoService {
|
||||
equipo.isImpresora
|
||||
? { ...datosBase, periferico: { id_periferico: equipo.id_periferico } }
|
||||
: {
|
||||
...datosBase,
|
||||
sistemaOperativo: {
|
||||
id_sistema_operativo: equipo.id_sistema_operativo,
|
||||
...datosBase,
|
||||
sistemaOperativo: {
|
||||
id_sistema_operativo: equipo.id_sistema_operativo,
|
||||
},
|
||||
procesador: { id_procesador: equipo.id_procesador },
|
||||
},
|
||||
procesador: { id_procesador: equipo.id_procesador },
|
||||
},
|
||||
);
|
||||
|
||||
let equip = await this.equipoRepository.save(nuevoEquipo);
|
||||
@@ -414,7 +414,6 @@ export class EquipoService {
|
||||
{ header: 'Observaciones', key: 'observaciones', width: 100 },
|
||||
{ header: 'Fecha Movimiento', key: 'fechaMovimiento', width: 70 },
|
||||
{ header: 'Usuario', key: 'user', width: 70 },
|
||||
|
||||
];
|
||||
|
||||
// =====================================
|
||||
@@ -477,10 +476,7 @@ export class EquipoService {
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=equipos.xlsx',
|
||||
);
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=equipos.xlsx');
|
||||
|
||||
await workbook.xlsx.write(res);
|
||||
res.end();
|
||||
@@ -1079,7 +1075,7 @@ export class EquipoService {
|
||||
return res;
|
||||
}
|
||||
|
||||
async ranking() {
|
||||
async ranking(year: number) {
|
||||
const equipos = await this.equipoRepository.find({
|
||||
relations: ['mov', 'mov.user'],
|
||||
});
|
||||
@@ -1092,7 +1088,14 @@ export class EquipoService {
|
||||
for (const equipo of equipos) {
|
||||
if (!equipo.mov || equipo.mov.length === 0) continue;
|
||||
|
||||
const ultimoMov = equipo.mov.sort(
|
||||
const movimientosDelAnno = equipo.mov.filter((mov) => {
|
||||
const fecha = new Date(mov.fechaMovimiento);
|
||||
return fecha.getFullYear() === year;
|
||||
});
|
||||
|
||||
if (movimientosDelAnno.length === 0) continue;
|
||||
|
||||
const ultimoMov = movimientosDelAnno.sort(
|
||||
(a, b) =>
|
||||
new Date(b.fechaMovimiento).getTime() -
|
||||
new Date(a.fechaMovimiento).getTime(),
|
||||
|
||||
Reference in New Issue
Block a user