Se corrigieron el xlsx, validación de contraseñas y cron
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -23,8 +23,9 @@ export class AuthService {
|
||||
registroDto.id_User,
|
||||
{
|
||||
nombre: registroDto.nombre,
|
||||
contraseña: registroDto.contraseña,
|
||||
contraseñaN: registroDto.contraseñaN,
|
||||
id_tipo_usuario: registroDto.tipoUsuario,
|
||||
contraseñaV: registroDto.contraseñaV,
|
||||
},
|
||||
);
|
||||
return update_data;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -21,9 +21,15 @@ export class UpdateUsuarioDto {
|
||||
@MinLength(5)
|
||||
@Transform(({ value }) => value.trim())
|
||||
@IsOptional()
|
||||
contraseña?: string;
|
||||
contraseñaN?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
tipoUsuario?: number;
|
||||
|
||||
@IsString()
|
||||
@MinLength(5)
|
||||
@Transform(({ value }) => value.trim())
|
||||
@IsOptional()
|
||||
contraseñaV?: string;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { CreateUsuarioDto } from './dto/create-usuario.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -25,7 +26,12 @@ export class UsuariosService {
|
||||
|
||||
async actualizarUsuario(
|
||||
id: number,
|
||||
datos: { nombre?: string; contraseña?: string; id_tipo_usuario?: number },
|
||||
datos: {
|
||||
nombre?: string;
|
||||
contraseñaN?: string;
|
||||
id_tipo_usuario?: number;
|
||||
contraseñaV?: string;
|
||||
},
|
||||
) {
|
||||
// Buscar al usuario
|
||||
const usuario = await this.usuarioRepository.findOne({
|
||||
@@ -43,8 +49,17 @@ export class UsuariosService {
|
||||
}
|
||||
|
||||
// Actualizar contraseña con hash
|
||||
if (datos.contraseña) {
|
||||
const hashed = await bcrypt.hash(datos.contraseña, 10);
|
||||
if (datos.contraseñaN && datos.contraseñaV) {
|
||||
const contraseñaValida = await bcrypt.compare(
|
||||
datos.contraseñaV,
|
||||
usuario.contraseña,
|
||||
);
|
||||
|
||||
if (!contraseñaValida) {
|
||||
throw new UnauthorizedException('Contraseña inválida');
|
||||
}
|
||||
|
||||
const hashed = await bcrypt.hash(datos.contraseñaN, 10);
|
||||
usuario.contraseña = hashed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user