Se agregarón usuarios Externos en Carga Individual

This commit is contained in:
2025-09-09 09:52:05 -06:00
parent d9550f1bf1
commit 6e12e580e1
3 changed files with 17 additions and 10 deletions
+11 -4
View File
@@ -27,10 +27,14 @@ export class ExcelController {
@Post('carga')
async cargaUsuario(@Request() req, @Body() usuario: CreateUsuarioDto) {
console.log('Usuario recibido:', usuario);
if (req.user.origen != 'LOAD') {
throw new BadRequestException('Origen no permitido para carga')
console.log('Datos del request:', req.user);
if (req.user.origen != 'LOAD' && req.user.origen!='EXTERNO') {
throw new Error('Origen no permitido para carga')
}
const alta = await this.usuarioService.cargaIndividual(usuario, req.user.origen, req.user.email);
if (!alta) {
throw new Error('No se pudo realizar la carga del usuario')
}
const alta = await this.usuarioService.cargaIndividual(usuario, req.user.origen)
console.log('Alta de usuario:', alta);
await this.movimientoService.updateStatus(alta.movId, 'SUCCESS')
@@ -41,6 +45,9 @@ export class ExcelController {
html: `<p>La carga de datos se ha realizado con éxito ${alta} </p>`,
});
await this.excelService.enviarInforme("LOAD","Carga Individual de datos en Servicios PCpuma",
`Se ha hecho una carga individual en el sistema por el usuario ${req.user.email}`)
if(alta.at){
await this.excelService.enviarInforme('AT',"Carga Individual de datos en Servicios PCpuma",
`Se ha hecho una carga individual en el sistema`)
@@ -95,7 +102,7 @@ export class ExcelController {
}
try {
const result = await this.excelService.loadFile(file.buffer);
const result = await this.excelService.loadFile(file.buffer,req.user.email);
//Actualizar el estado de los movimientos
if (!result) {
this.mailService.sendMail({
+3 -3
View File
@@ -197,7 +197,7 @@ export class ExcelService {
/**
* Valida y luego persiste usuarios y relaciones básicas
*/
async loadFile(buffer: Buffer) {
async loadFile(buffer: Buffer, user:string) {
const file = await this.parseFile(buffer);
const status = this.validateRows(file);
const errs = status.errors;
@@ -223,8 +223,8 @@ export class ExcelService {
queryRunner,
'LOAD',
'LOADING',
undefined,
'CARGA MASIVA DE USUARIOS',
'Caraga masiva de usuarios hecha por: ' + user,
`CARGA MASIVA DE USUARIOS`,
);
// 🔹 1. Pre-cargar cuentas/rfc ya existentes
+3 -3
View File
@@ -460,7 +460,7 @@ export class UsuariosService {
}
async cargaIndividual(usuario: CreateUsuarioDto, origen: string) {
async cargaIndividual(usuario: CreateUsuarioDto, origen: string, user:string) {
console.log('Iniciando carga individual para usuario:', usuario);
const queryRunner = this.usuarioRepository.manager.connection.createQueryRunner();
await queryRunner.connect();
@@ -476,7 +476,7 @@ export class UsuariosService {
throw new Error('Ya existe este usuario');
}
const mov = await this.movimientoService.logger(queryRunner, origen, 'LOADING', undefined, 'CARGA INDIVIDUAL DE USUARIOS');
const mov = await this.movimientoService.logger(queryRunner, origen, 'LOADING', 'la carga se hizo por: '+user , 'CARGA INDIVIDUAL DE USUARIOS');
let genero: Genero | null = null;
if (usuario.genero === 'M' || usuario.genero === 'F') {
@@ -681,7 +681,7 @@ export class UsuariosService {
} catch (error) {
await queryRunner.rollbackTransaction();
throw error;
throw new Error("Error en la carga individual: " + error.message);
} finally {
await queryRunner.release();
}