Se corrigieron el xlsx, validación de contraseñas y cron
This commit is contained in:
@@ -130,9 +130,14 @@ export class EquipoController {
|
||||
return this.equipoService.findAllProcesadorTipoEquipos();
|
||||
}
|
||||
|
||||
// @Post('daily')
|
||||
// async daily() {
|
||||
// return await this.equipoService.llenadoDeAntiguedad();
|
||||
// }
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('reporteXLSX')
|
||||
async generarReporte(@Res() res: Response) {
|
||||
async generarReporte(@Res({ passthrough: true }) res: Response) {
|
||||
try {
|
||||
await this.equipoService.createEcxel(res);
|
||||
} catch (error) {
|
||||
|
||||
@@ -365,7 +365,7 @@ export class EquipoService {
|
||||
|
||||
@Cron('0 0 0 * * *')
|
||||
async llenadoDeAntiguedad() {
|
||||
await this.equipoRepository
|
||||
const result = await this.equipoRepository
|
||||
.createQueryBuilder()
|
||||
.update(Equipo)
|
||||
.set({
|
||||
@@ -380,13 +380,21 @@ export class EquipoService {
|
||||
`,
|
||||
})
|
||||
.execute();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async exportarReporteAExcel(data: any, res: Response) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
let count = 1;
|
||||
|
||||
for (const key of Object.keys(data)) {
|
||||
const sheetName = key.substring(0, 30); // Excel limita a 30 caracteres
|
||||
let sheetName = key.substring(0, 30);
|
||||
|
||||
if (workbook.getWorksheet(sheetName)) {
|
||||
sheetName = `${sheetName}_${count++}`;
|
||||
}
|
||||
|
||||
const sheet = workbook.addWorksheet(sheetName);
|
||||
|
||||
const rows = data[key];
|
||||
@@ -396,34 +404,28 @@ export class EquipoService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Obtener columnas automáticamente
|
||||
const headers = Object.keys(rows[0]);
|
||||
|
||||
// Crear encabezado
|
||||
sheet.addRow(headers);
|
||||
|
||||
// Agregar filas
|
||||
for (const row of rows) {
|
||||
sheet.addRow(headers.map((h) => row[h]));
|
||||
}
|
||||
|
||||
// Estilo básico
|
||||
sheet.getRow(1).font = { bold: true };
|
||||
sheet.getRow(1).alignment = { horizontal: 'center' };
|
||||
sheet.columns.forEach((col) => {
|
||||
col.width = 35;
|
||||
});
|
||||
sheet.columns.forEach((col) => (col.width = 35));
|
||||
}
|
||||
|
||||
// Enviar el archivo al cliente
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=reporte.xlsx');
|
||||
|
||||
await workbook.xlsx.write(res);
|
||||
res.end();
|
||||
res.status(200).end();
|
||||
}
|
||||
|
||||
async createReport() {
|
||||
|
||||
Reference in New Issue
Block a user