se actualizo la funcion de carga masiva y se quitaron console logs
This commit is contained in:
+56
-56
@@ -41,22 +41,22 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCorreo(id:string, nombreNuevo:string){
|
async updateCorreo(id: string, nombreNuevo: string) {
|
||||||
console.log("id: ", id, "nombre: ", nombreNuevo)
|
|
||||||
const usuarios=await this.userRepo.findOne({where:{id_usuario:id}})
|
const usuarios = await this.userRepo.findOne({ where: { id_usuario: id } })
|
||||||
console.log(usuarios)
|
|
||||||
if(!usuarios){throw new Error("usuaro no existe")}
|
if (!usuarios) { throw new Error("usuaro no existe") }
|
||||||
usuarios.correo=nombreNuevo;
|
usuarios.correo = nombreNuevo;
|
||||||
|
|
||||||
return await this.userRepo.save(usuarios);
|
return await this.userRepo.save(usuarios);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async all(){
|
async all() {
|
||||||
|
|
||||||
const usuarios=await this.userRepo.find()
|
const usuarios = await this.userRepo.find()
|
||||||
console.log(usuarios)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async register(dto: RegisterDto) {
|
async register(dto: RegisterDto) {
|
||||||
@@ -94,14 +94,14 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async white(dto: WhiteDto) {
|
async white(dto: WhiteDto) {
|
||||||
// 1) Verificar duplicado
|
// 1) Verificar duplicado
|
||||||
const exists = await this.userRepo.findOne({ where: { correo: dto.email } });
|
const exists = await this.userRepo.findOne({ where: { correo: dto.email } });
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw new ConflictException('El correo ya está registrado');
|
throw new ConflictException('El correo ya está registrado');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let origen = await this.origenRepo.findOne({ where: { origen: dto.origen } });
|
let origen = await this.origenRepo.findOne({ where: { origen: dto.origen } });
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ export class AuthService {
|
|||||||
// 3) Crear entidad Usuario
|
// 3) Crear entidad Usuario
|
||||||
const user = this.userRepo.create({
|
const user = this.userRepo.create({
|
||||||
correo: dto.email,
|
correo: dto.email,
|
||||||
contraseña:undefined,
|
contraseña: undefined,
|
||||||
origen: origen,
|
origen: origen,
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -129,55 +129,55 @@ export class AuthService {
|
|||||||
|
|
||||||
|
|
||||||
async validateGoogleUser(email: string) {
|
async validateGoogleUser(email: string) {
|
||||||
const user = await this.userRepo.findOne({ where: { correo: email }, relations: ['origen'] });
|
const user = await this.userRepo.findOne({ where: { correo: email }, relations: ['origen'] });
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// No permitir crear cuenta
|
// No permitir crear cuenta
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.contraseña) {
|
||||||
|
// Usuario existe pero nunca puso contraseña → permitirle definirla
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
needsPassword: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usuario con contraseña → login normal
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.contraseña) {
|
//Poner contraseñas
|
||||||
// Usuario existe pero nunca puso contraseña → permitirle definirla
|
// auth.service.ts
|
||||||
|
async setPassword(dto: SetPasswordDto) {
|
||||||
|
const user = await this.userRepo.findOne({
|
||||||
|
where: { correo: dto.email },
|
||||||
|
relations: ['origen'],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new UnauthorizedException('Usuario no encontrado');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.contraseña) {
|
||||||
|
throw new ConflictException('Este usuario ya tiene contraseña');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash contraseña nueva
|
||||||
|
const hash = await bcrypt.hash(dto.password, 10);
|
||||||
|
|
||||||
|
user.contraseña = hash;
|
||||||
|
const updated = await this.userRepo.save(user);
|
||||||
|
|
||||||
|
// Retornar con JWT inmediato (login automático)
|
||||||
|
const payload = { sub: updated.id_usuario, email: updated.correo, tipo: updated.origen.origen };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...user,
|
access_token: this.jwtService.sign(payload),
|
||||||
needsPassword: true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usuario con contraseña → login normal
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Poner contraseñas
|
|
||||||
// auth.service.ts
|
|
||||||
async setPassword(dto: SetPasswordDto) {
|
|
||||||
const user = await this.userRepo.findOne({
|
|
||||||
where: { correo: dto.email },
|
|
||||||
relations: ['origen'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new UnauthorizedException('Usuario no encontrado');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.contraseña) {
|
|
||||||
throw new ConflictException('Este usuario ya tiene contraseña');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash contraseña nueva
|
|
||||||
const hash = await bcrypt.hash(dto.password, 10);
|
|
||||||
|
|
||||||
user.contraseña = hash;
|
|
||||||
const updated = await this.userRepo.save(user);
|
|
||||||
|
|
||||||
// Retornar con JWT inmediato (login automático)
|
|
||||||
const payload = { sub: updated.id_usuario, email: updated.correo, tipo: updated.origen.origen };
|
|
||||||
|
|
||||||
return {
|
|
||||||
access_token: this.jwtService.sign(payload),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import { AuthGuard } from '@nestjs/passport';
|
|||||||
export class GoogleAuthGuard extends AuthGuard('google') {
|
export class GoogleAuthGuard extends AuthGuard('google') {
|
||||||
handleRequest(err, user, info, context) {
|
handleRequest(err, user, info, context) {
|
||||||
const res = context.switchToHttp().getResponse();
|
const res = context.switchToHttp().getResponse();
|
||||||
console.log("usuario: ", user);
|
|
||||||
console.log("error: ", err);
|
|
||||||
console.log("info: ", info);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
// redirige directamente y corta la ejecución
|
// redirige directamente y corta la ejecución
|
||||||
res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
|
res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return user; // si existe, sigue normalmente
|
return user; // si existe, sigue normalmente
|
||||||
|
|||||||
@@ -37,12 +37,11 @@ export class ExcelController {
|
|||||||
private readonly movimientoService: MovimientoService,
|
private readonly movimientoService: MovimientoService,
|
||||||
private readonly mailService: MailService,
|
private readonly mailService: MailService,
|
||||||
private readonly usuarioService: UsuariosService, // Asegúrate de importar el servicio de correo
|
private readonly usuarioService: UsuariosService, // Asegúrate de importar el servicio de correo
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
@Post('carga')
|
@Post('carga')
|
||||||
async cargaUsuario(@Request() req, @Body() usuario: CreateUsuarioDto) {
|
async cargaUsuario(@Request() req, @Body() usuario: CreateUsuarioDto) {
|
||||||
console.log('Usuario recibido:', usuario);
|
|
||||||
console.log('Datos del request:', req.user);
|
|
||||||
if (req.user.origen != 'LOAD' && req.user.origen != 'EXTERNO') {
|
if (req.user.origen != 'LOAD' && req.user.origen != 'EXTERNO') {
|
||||||
throw new Error('Origen no permitido para carga');
|
throw new Error('Origen no permitido para carga');
|
||||||
}
|
}
|
||||||
@@ -54,7 +53,6 @@ export class ExcelController {
|
|||||||
if (!alta) {
|
if (!alta) {
|
||||||
throw new Error('No se pudo realizar la carga del usuario');
|
throw new Error('No se pudo realizar la carga del usuario');
|
||||||
}
|
}
|
||||||
console.log('Alta de usuario:', alta);
|
|
||||||
await this.movimientoService.updateStatus(alta.movId, 'SUCCESS');
|
await this.movimientoService.updateStatus(alta.movId, 'SUCCESS');
|
||||||
|
|
||||||
await this.excelService.enviarInforme(
|
await this.excelService.enviarInforme(
|
||||||
@@ -154,7 +152,6 @@ export class ExcelController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result.id_movimiento);
|
|
||||||
await this.movimientoService.updateStatus(
|
await this.movimientoService.updateStatus(
|
||||||
result.id_movimiento,
|
result.id_movimiento,
|
||||||
'SUCCESS',
|
'SUCCESS',
|
||||||
@@ -217,8 +214,6 @@ export class ExcelController {
|
|||||||
@ExcelDocumentation.downloadExcel()
|
@ExcelDocumentation.downloadExcel()
|
||||||
async downloadData(@Request() req, @Res() res: Response) {
|
async downloadData(@Request() req, @Res() res: Response) {
|
||||||
const origen = req.user.origen; // ahora sí existe
|
const origen = req.user.origen; // ahora sí existe
|
||||||
console.log('Origen de descarga:', origen);
|
|
||||||
console.log('Usuario:', req.user);
|
|
||||||
|
|
||||||
if (origen == 'SOLICITA') {
|
if (origen == 'SOLICITA') {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export class ExcelService {
|
|||||||
private readonly dataSource: DataSource,
|
private readonly dataSource: DataSource,
|
||||||
|
|
||||||
// … inyecta otros repositorios si los usarás
|
// … inyecta otros repositorios si los usarás
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/** Lee el buffer del Excel y devuelve un arreglo de filas tipadas */
|
/** Lee el buffer del Excel y devuelve un arreglo de filas tipadas */
|
||||||
private async parseFile(buffer: Buffer): Promise<UsuarioRow[]> {
|
private async parseFile(buffer: Buffer): Promise<UsuarioRow[]> {
|
||||||
@@ -672,7 +672,6 @@ export class ExcelService {
|
|||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
const tablaCompleta = header + rows;
|
const tablaCompleta = header + rows;
|
||||||
console.log('rows:', rows);
|
|
||||||
return tablaCompleta;
|
return tablaCompleta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -877,7 +876,6 @@ export class ExcelService {
|
|||||||
`Se ha realizado una carga de usuarios en el sistema. Nuevos: ${data?.nuevos ?? 0}, Actualizados: ${data?.actualizados ?? 0}`,
|
`Se ha realizado una carga de usuarios en el sistema. Nuevos: ${data?.nuevos ?? 0}, Actualizados: ${data?.actualizados ?? 0}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`Correo enviados`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async enviarInforme(
|
async enviarInforme(
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ export class MailController {
|
|||||||
const result =
|
const result =
|
||||||
await this.mailService.sendMail(body)
|
await this.mailService.sendMail(body)
|
||||||
.then((value) => {
|
.then((value) => {
|
||||||
console.log("Se mandaron los correos", value);
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
throw new Error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ export class MailService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
console.log(mailOptions);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,27 +101,27 @@ export class MovimientoService {
|
|||||||
): Promise<{ move: any[]; button: boolean; total?: number; lastPage?: number }> {
|
): Promise<{ move: any[]; button: boolean; total?: number; lastPage?: number }> {
|
||||||
|
|
||||||
if (origen === 'LOAD') {
|
if (origen === 'LOAD') {
|
||||||
const [movimientos, total] = await this.movRepo.findAndCount({
|
const [movimientos, total] = await this.movRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
origen: { origen: 'LOAD' },
|
origen: { origen: 'LOAD' },
|
||||||
status: 'SUCCESS',
|
status: 'SUCCESS',
|
||||||
reporte: 'CARGA MASIVA DE USUARIOS',
|
reporte: 'CARGA MASIVA DE USUARIOS',
|
||||||
},
|
},
|
||||||
skip: (page - 1) * limit,
|
skip: (page - 1) * limit,
|
||||||
take: limit,
|
take: limit,
|
||||||
order: { fecha_mov: 'DESC' }, // opcional
|
order: { fecha_mov: 'DESC' }, // opcional
|
||||||
});
|
});
|
||||||
|
|
||||||
// si quieres incluir también mov y mov2 en la misma paginación:
|
// si quieres incluir también mov y mov2 en la misma paginación:
|
||||||
// const todosLosMovimientos = [...movimientos, ...mov, ...mov2]; (y luego slice)
|
// const todosLosMovimientos = [...movimientos, ...mov, ...mov2]; (y luego slice)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
move: movimientos,
|
move: movimientos,
|
||||||
button: false,
|
button: false,
|
||||||
total,
|
total,
|
||||||
lastPage: Math.ceil(total / limit),
|
lastPage: Math.ceil(total / limit),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const statusFieldMap = {
|
const statusFieldMap = {
|
||||||
AT: 'ATStatus',
|
AT: 'ATStatus',
|
||||||
RED: 'RedStatus',
|
RED: 'RedStatus',
|
||||||
@@ -169,13 +169,11 @@ export class MovimientoService {
|
|||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log('movimientos:', mov2)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const todosLosMovimientos = [...movimientos, ...mov, ...mov2];
|
const todosLosMovimientos = [...movimientos, ...mov, ...mov2];
|
||||||
console.log(todosLosMovimientos)
|
|
||||||
return { move: todosLosMovimientos, button: false };
|
return { move: todosLosMovimientos, button: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -378,7 +378,6 @@ export class UsuariosService {
|
|||||||
origen: string,
|
origen: string,
|
||||||
user: string,
|
user: string,
|
||||||
) {
|
) {
|
||||||
console.log('Iniciando carga individual para usuario:', usuario);
|
|
||||||
const queryRunner =
|
const queryRunner =
|
||||||
this.usuarioRepository.manager.connection.createQueryRunner();
|
this.usuarioRepository.manager.connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
@@ -425,7 +424,6 @@ export class UsuariosService {
|
|||||||
where: { carrera: '' },
|
where: { carrera: '' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(carrera);
|
|
||||||
} else {
|
} else {
|
||||||
carrera = await queryRunner.manager.findOne(Carrera, {
|
carrera = await queryRunner.manager.findOne(Carrera, {
|
||||||
where: { carrera: '' },
|
where: { carrera: '' },
|
||||||
@@ -452,7 +450,6 @@ export class UsuariosService {
|
|||||||
contraseña: usuario.contraseña ?? null, // Asegúrate de manejar la contraseña adecuadamente
|
contraseña: usuario.contraseña ?? null, // Asegúrate de manejar la contraseña adecuadamente
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(nuevo);
|
|
||||||
|
|
||||||
const savedUser = await queryRunner.manager.save(nuevo);
|
const savedUser = await queryRunner.manager.save(nuevo);
|
||||||
|
|
||||||
@@ -611,7 +608,6 @@ export class UsuariosService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(savedUser);
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
|
|
||||||
return { saved: savedUser, movId: mov.id_mov, at, correo, red, solicita };
|
return { saved: savedUser, movId: mov.id_mov, at, correo, red, solicita };
|
||||||
|
|||||||
Reference in New Issue
Block a user