Se agregó envío de correos
This commit is contained in:
+146
-127
@@ -1,5 +1,21 @@
|
||||
// src/excel/excel.controller.ts
|
||||
import { Controller, Post, Get, UseGuards, Request, Res, UploadedFile, UseInterceptors, HttpStatus, Param, ParseIntPipe, Body, BadRequestException, Delete, Query } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Get,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
HttpStatus,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Body,
|
||||
BadRequestException,
|
||||
Delete,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
@@ -20,61 +36,75 @@ export class ExcelController {
|
||||
private readonly excelService: ExcelService,
|
||||
private readonly movimientoService: MovimientoService,
|
||||
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')
|
||||
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') {
|
||||
throw new Error('Origen no permitido para carga')
|
||||
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);
|
||||
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')
|
||||
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("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 de ${usuario.tipo_usuario}`)
|
||||
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 de ${usuario.tipo_usuario}`,
|
||||
);
|
||||
}
|
||||
if(alta.red){
|
||||
await this.excelService.enviarInforme('RED',"Carga Individual de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`)
|
||||
if (alta.red) {
|
||||
await this.excelService.enviarInforme(
|
||||
'RED',
|
||||
'Carga Individual de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(alta.solicita){
|
||||
await this.excelService.enviarInforme('SOLICITA',"Carga Individual de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}` )
|
||||
if (alta.solicita) {
|
||||
await this.excelService.enviarInforme(
|
||||
'SOLICITA',
|
||||
'Carga Individual de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`,
|
||||
);
|
||||
}
|
||||
|
||||
if(alta.correo){
|
||||
await this.excelService.enviarInforme('CORREO',"Carga Individual de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`)
|
||||
|
||||
if (alta.correo) {
|
||||
await this.excelService.enviarInforme(
|
||||
'CORREO',
|
||||
'Carga Individual de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Post('verify')
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@ExcelDocumentation.verifyExcel()
|
||||
async verifyExcel(@UploadedFile() file: Express.Multer.File, @Request() req) {
|
||||
const userId: number = req.user.userId; // ahora sí existe
|
||||
const userId: number = req.user.userId; // ahora sí existe
|
||||
const status = await this.excelService.validateFile(file.buffer);
|
||||
const errors = status.errors;
|
||||
await this.movimientoService.log(
|
||||
|
||||
'VERIFY',
|
||||
errors.length ? 'FAILED' : 'SUCCESS',
|
||||
errors.join('; ')
|
||||
errors.join('; '),
|
||||
);
|
||||
return { valid: errors.length === 0, errors };
|
||||
}
|
||||
@@ -89,20 +119,22 @@ export class ExcelController {
|
||||
await this.movimientoService.log(
|
||||
origen,
|
||||
'FAILED',
|
||||
'Origen no permitido para carga'
|
||||
'Origen no permitido para carga',
|
||||
);
|
||||
throw new Error('Origen no permitido para carga.');
|
||||
}
|
||||
try {
|
||||
|
||||
const result = await this.excelService.loadFile(file.buffer,req.user.email);
|
||||
const result = await this.excelService.loadFile(
|
||||
file.buffer,
|
||||
req.user.email,
|
||||
);
|
||||
//Actualizar el estado de los movimientos
|
||||
if (!result) {
|
||||
this.mailService.sendMail({
|
||||
to: req.user.email, // Asegúrate de que el usuario tenga un email
|
||||
subject: 'Carga de datos Fallida',
|
||||
text: "No se pudieron subir datos.",
|
||||
html: '<p>No se pudieron subir datos.</p>',
|
||||
text: 'No se pudieron subir datos.',
|
||||
html: '',
|
||||
});
|
||||
throw new Error('No se pudo procesar el archivo.');
|
||||
}
|
||||
@@ -111,70 +143,72 @@ export class ExcelController {
|
||||
this.mailService.sendMail({
|
||||
to: req.user.email, // Asegúrate de que el usuario tenga un email
|
||||
subject: 'Carga de datos Fallida',
|
||||
text: "No se pudieron subir datos.",
|
||||
html: `<p> Se han insertado ${result.inserted} registros.</p>
|
||||
<p>Errores encontrados:</p>
|
||||
<ul>${result.errors.map(error => `<li>${error}</li>`).join('')}</ul>`,
|
||||
text:
|
||||
'No se pudieron subir datos.' +
|
||||
`Se han insertado ${result.inserted} registros.
|
||||
Errores encontrados:
|
||||
${result.errors.map((error) => `<li>${error}</li>`).join('')}`,
|
||||
html: '',
|
||||
});
|
||||
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
console.log(result.id_movimiento)
|
||||
console.log(result.id_movimiento);
|
||||
await this.movimientoService.updateStatus(
|
||||
result.id_movimiento,
|
||||
'SUCCESS',
|
||||
`inserted=${result.inserted}`
|
||||
`inserted=${result.inserted}`,
|
||||
);
|
||||
|
||||
this.mailService.sendMail({
|
||||
to: req.user.email, // Asegúrate de que el usuario tenga un email
|
||||
subject: 'Carga de datos exitosa',
|
||||
text: "La carga de datos se ha realizado con éxito.",
|
||||
html:
|
||||
`<p>La carga de datos se ha realizado con éxito. Se han insertado ${result.inserted} registros.</p>
|
||||
text: 'La carga de datos se ha realizado con éxito.',
|
||||
html: `<p> La carga de datos se ha realizado con éxito. Se han insertado ${result.inserted} registros.</p>
|
||||
<p>Usuarios At: ${result.conteoTiposAt}</p>
|
||||
<p>Usuarios Red: ${result.conteoTiposRed}</p>
|
||||
<p>Usuarios Solicita: ${result.conteoTiposSolicita}</p>
|
||||
<p>Usuarios Correo: ${result.conteoTiposCorreo}</p>
|
||||
<ul>${result.errors.map(error => `<li>${error}</li>`).join('')}</ul>`,
|
||||
<ul>${result.errors.map((error) => `<li>${error}</li>`).join('')}</ul>`,
|
||||
});
|
||||
|
||||
// await this.excelService.enviarCargaMasiva();
|
||||
|
||||
if(result.conteoTiposAt>0){
|
||||
|
||||
await this.excelService.enviarInforme('AT',"Carga de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga en el sistema de \n ${result.conteoTiposAt} usarios`)
|
||||
if (result.conteoTiposAt > 0) {
|
||||
await this.excelService.enviarInforme(
|
||||
'AT',
|
||||
'Carga de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga en el sistema de \n ${result.conteoTiposAt} usarios`,
|
||||
);
|
||||
}
|
||||
if(result.conteoTiposRed>0){
|
||||
await this.excelService.enviarInforme('RED',"Carga de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposRed} usarios`)
|
||||
if (result.conteoTiposRed > 0) {
|
||||
await this.excelService.enviarInforme(
|
||||
'RED',
|
||||
'Carga de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposRed} usarios`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(result.conteoTiposSolicita>0){
|
||||
await this.excelService.enviarInforme('SOLICITA',"Carga de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposSolicita} usarios` )
|
||||
if (result.conteoTiposSolicita > 0) {
|
||||
await this.excelService.enviarInforme(
|
||||
'SOLICITA',
|
||||
'Carga de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposSolicita} usarios`,
|
||||
);
|
||||
}
|
||||
|
||||
if(result.conteoTiposCorreo>0){
|
||||
await this.excelService.enviarInforme('CORREO',"Carga de datos en Servicios PCpuma",
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposCorreo} usarios`)
|
||||
|
||||
if (result.conteoTiposCorreo > 0) {
|
||||
await this.excelService.enviarInforme(
|
||||
'CORREO',
|
||||
'Carga de datos en Servicios PCpuma',
|
||||
`Se ha hecho una carga en el sistema \n ${result.conteoTiposCorreo} usarios`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return result
|
||||
|
||||
return result;
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
|
||||
'LOAD',
|
||||
'FAILED',
|
||||
err.message
|
||||
);
|
||||
await this.movimientoService.log('LOAD', 'FAILED', err.message);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -190,42 +224,45 @@ export class ExcelController {
|
||||
try {
|
||||
const csv = await this.excelService.generateCsvSolicita();
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'SUCCESS',
|
||||
'descarga de csv',
|
||||
`size=${csv.length}`
|
||||
`size=${csv.length}`,
|
||||
);
|
||||
return res
|
||||
.status(HttpStatus.OK)
|
||||
.header('Content-Type', 'text/csv')
|
||||
.header('Content-Disposition', 'attachment; filename="usuarios_solicita.csv"')
|
||||
.header(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="usuarios_solicita.csv"',
|
||||
)
|
||||
.send(csv);
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
origen,
|
||||
'FAILED',
|
||||
'Origen no permitido para descarga'
|
||||
'Origen no permitido para descarga',
|
||||
);
|
||||
return res
|
||||
.status(HttpStatus.FORBIDDEN)
|
||||
.json({ statusCode: 403, message: 'Origen no permitido para descarga.' });
|
||||
.json({
|
||||
statusCode: 403,
|
||||
message: 'Origen no permitido para descarga.',
|
||||
});
|
||||
}
|
||||
} else if (origen == 'CORREO' || origen == 'LOAD') {
|
||||
try {
|
||||
const csv = await this.excelService.generateCsvCorreo();
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'SUCCESS',
|
||||
'descarga de csv',
|
||||
`size=${csv.length}`
|
||||
`size=${csv.length}`,
|
||||
);
|
||||
let filename
|
||||
let filename;
|
||||
if (origen == 'CORREO') {
|
||||
filename = 'usuarios_correo.csv';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
filename = 'usuarios.csv';
|
||||
}
|
||||
|
||||
@@ -235,12 +272,7 @@ export class ExcelController {
|
||||
.header('Content-Disposition', `attachment; filename="${filename}"`)
|
||||
.send(csv);
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'FAILED',
|
||||
err.message
|
||||
);
|
||||
await this.movimientoService.log(origen, 'FAILED', err.message);
|
||||
return res
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.json({ statusCode: 500, message: 'Error generando descarga.' });
|
||||
@@ -249,24 +281,21 @@ export class ExcelController {
|
||||
try {
|
||||
const csv = await this.excelService.generateCsvAT();
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'SUCCESS',
|
||||
'descarga de csv',
|
||||
`size=${csv.length}`
|
||||
`size=${csv.length}`,
|
||||
);
|
||||
return res
|
||||
.status(HttpStatus.OK)
|
||||
.header('Content-Type', 'text/csv')
|
||||
.header('Content-Disposition', 'attachment; filename="usuarios_AT.csv"')
|
||||
.header(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="usuarios_AT.csv"',
|
||||
)
|
||||
.send(csv);
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'FAILED',
|
||||
err.message
|
||||
);
|
||||
await this.movimientoService.log(origen, 'FAILED', err.message);
|
||||
return res
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.json({ statusCode: 500, message: 'Error generando descarga.' });
|
||||
@@ -275,51 +304,49 @@ export class ExcelController {
|
||||
try {
|
||||
const csv = await this.excelService.generateCsvRed();
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'SUCCESS',
|
||||
'descarga de csv',
|
||||
`size=${csv.length}`
|
||||
`size=${csv.length}`,
|
||||
);
|
||||
return res
|
||||
.status(HttpStatus.OK)
|
||||
.header('Content-Type', 'text/csv')
|
||||
.header('Content-Disposition', 'attachment; filename="usuarios_red.csv"')
|
||||
.header(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="usuarios_red.csv"',
|
||||
)
|
||||
.send(csv);
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'FAILED',
|
||||
err.message
|
||||
);
|
||||
await this.movimientoService.log(origen, 'FAILED', err.message);
|
||||
return res
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.json({ statusCode: 500, message: 'Error generando descarga.' });
|
||||
}
|
||||
} else {
|
||||
await this.movimientoService.log(
|
||||
|
||||
origen,
|
||||
'FAILED',
|
||||
'Origen no permitido para descarga'
|
||||
'Origen no permitido para descarga',
|
||||
);
|
||||
return res
|
||||
.status(HttpStatus.FORBIDDEN)
|
||||
.json({ statusCode: 403, message: 'Origen no permitido para descarga.' });
|
||||
.json({
|
||||
statusCode: 403,
|
||||
message: 'Origen no permitido para descarga.',
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Agregarlo en su propio controller
|
||||
@Get('movimientos')
|
||||
async getMovimientos(
|
||||
@Request() req,
|
||||
@Query('page') page: number,
|
||||
@Query('limit') limit: number,
|
||||
) {
|
||||
return this.movimientoService.findAll(req.user.origen, page, limit);
|
||||
}
|
||||
async getMovimientos(
|
||||
@Request() req,
|
||||
@Query('page') page: number,
|
||||
@Query('limit') limit: number,
|
||||
) {
|
||||
return this.movimientoService.findAll(req.user.origen, page, limit);
|
||||
}
|
||||
|
||||
@Post('activar-servicios/:id_movimiento')
|
||||
async activarServicios(
|
||||
@@ -337,22 +364,14 @@ async getMovimientos(
|
||||
return { message: 'Servicios activados correctamente' };
|
||||
}
|
||||
|
||||
|
||||
@Get('cargaIndividual')
|
||||
async cargarIndividual(
|
||||
@Request() req) {
|
||||
async cargarIndividual(@Request() req) {
|
||||
const origen = req.user.origen; // ahora sí existe
|
||||
return this.movimientoService.findAllCargaIndv(origen);
|
||||
|
||||
}
|
||||
|
||||
// @Delete()
|
||||
// async borrar(){
|
||||
// return await this.excelService.borrarUsers()
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+483
-436
File diff suppressed because it is too large
Load Diff
+216
-167
@@ -2,7 +2,14 @@ import { Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { CreateUsuarioDto } from './dto/create-usuario.dto';
|
||||
import { UpdateUsuarioDto } from './dto/update-usuario.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Carrera, CarreraUsuario, Genero, TipoUsuario, Usuario, UsuarioTipoUsuario } from 'src/entities/entities';
|
||||
import {
|
||||
Carrera,
|
||||
CarreraUsuario,
|
||||
Genero,
|
||||
TipoUsuario,
|
||||
Usuario,
|
||||
UsuarioTipoUsuario,
|
||||
} from 'src/entities/entities';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ServActivos } from './entities/servActivos.entitie';
|
||||
import { MovimientoService } from 'src/movimiento/movimiento.service';
|
||||
@@ -11,9 +18,6 @@ import { error } from 'console';
|
||||
import { Cron } from '@nestjs/schedule';
|
||||
import { ExcelService } from 'src/excel/excel.service';
|
||||
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class UsuariosService {
|
||||
private readonly logger = new Logger(UsuariosService.name);
|
||||
@@ -36,44 +40,32 @@ export class UsuariosService {
|
||||
private readonly movimientoService: MovimientoService,
|
||||
private readonly mailService: MailService,
|
||||
private readonly excelService: ExcelService, // Asegúrate de importar el servicio de Excel
|
||||
|
||||
) { }
|
||||
) {}
|
||||
|
||||
altaIndividual(createUsuarioDto: CreateUsuarioDto) {
|
||||
return 'This action adds a new usuario';
|
||||
}
|
||||
|
||||
|
||||
|
||||
async findByMov(id:number){
|
||||
async findByMov(id: number) {
|
||||
const usuarios = await this.usuarioRepository.find({
|
||||
where: {
|
||||
//movimiento:{id_mov:id},
|
||||
//movimiento:{id_mov:id},
|
||||
|
||||
servActivo: {
|
||||
PrestamosStatus: 'Inactivo', // solo los que no tienen servicio activo
|
||||
Prestamos: true, // solo los que tienen el servicio de préstamos activo
|
||||
}
|
||||
|
||||
},
|
||||
relations: [
|
||||
'usuarioTipos',
|
||||
'usuarioTipos.tipoUsuario',
|
||||
'servActivo'
|
||||
],
|
||||
|
||||
},
|
||||
},
|
||||
relations: ['usuarioTipos', 'usuarioTipos.tipoUsuario', 'servActivo'],
|
||||
});
|
||||
if(!usuarios)throw new Error("No existe suauarios relacionados a ese movimiento");
|
||||
if (!usuarios)
|
||||
throw new Error('No existe suauarios relacionados a ese movimiento');
|
||||
return usuarios;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
async findOneStatus(noCuenta: string) {
|
||||
const usuario = await this.usuarioRepository.findOne({
|
||||
where: { num_cuenta: noCuenta },
|
||||
|
||||
});
|
||||
|
||||
if (!usuario) {
|
||||
@@ -109,44 +101,33 @@ export class UsuariosService {
|
||||
resultado.push({
|
||||
servicio: nombre,
|
||||
status: 'Inactivo',
|
||||
fecha_activacion: "",
|
||||
fecha_activacion: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
await mapServicio('Red', servActivo.RedStatus);
|
||||
await mapServicio('Correo', servActivo.CorreoStatus);
|
||||
await mapServicio('Préstamo de equipo PC Puma', servActivo.PrestamosStatus);
|
||||
await mapServicio('Préstamo de equipo en CEDETEC', servActivo.ATStatus);
|
||||
|
||||
|
||||
|
||||
if (resultado.length === 0) {
|
||||
return [{
|
||||
servicio: 'Ninguno',
|
||||
status: 'No hay servicios activos para este usuario',
|
||||
fecha_activacion: null,
|
||||
}];
|
||||
return [
|
||||
{
|
||||
servicio: 'Ninguno',
|
||||
status: 'No hay servicios activos para este usuario',
|
||||
fecha_activacion: null,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { resultado, usuario: usuario.nombre };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
update(id: number, updateUsuarioDto: UpdateUsuarioDto) {
|
||||
return `This action updates a #${id} usuario`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Cron('0 0 0 10,25 * *')
|
||||
async tareaMensual() {
|
||||
this.logger.log('Ejecutando consulta mensual de profesores');
|
||||
@@ -158,10 +139,9 @@ export class UsuariosService {
|
||||
'SISTEMA',
|
||||
'LOADING',
|
||||
'Enviando solicitud de consulta masiva de profesores al WebService',
|
||||
'CARGA MASIVA WEB SERVICE'
|
||||
'CARGA MASIVA WEB SERVICE',
|
||||
);
|
||||
|
||||
|
||||
interface DatosEntrada {
|
||||
Nombre: string;
|
||||
ApellidoPaterno: string;
|
||||
@@ -187,44 +167,51 @@ export class UsuariosService {
|
||||
|
||||
const apiUrl = process.env.API_URL;
|
||||
if (!apiUrl) {
|
||||
console.error("API_URL no está definida en las variables de entorno");
|
||||
console.error('API_URL no está definida en las variables de entorno');
|
||||
return;
|
||||
}
|
||||
|
||||
const entrada: DatosEntrada = {
|
||||
Nombre: "",
|
||||
ApellidoPaterno: "",
|
||||
ApellidoMaterno: "",
|
||||
NumeroTrabajador: "",
|
||||
RFC: ""
|
||||
Nombre: '',
|
||||
ApellidoPaterno: '',
|
||||
ApellidoMaterno: '',
|
||||
NumeroTrabajador: '',
|
||||
RFC: '',
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(entrada)
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(entrada),
|
||||
});
|
||||
|
||||
if (response.status === 400) {
|
||||
const errorText = await response.text();
|
||||
console.error("Error 400:", errorText);
|
||||
console.error('Error 400:', errorText);
|
||||
return;
|
||||
} else if (response.status === 204) {
|
||||
console.log("No se encontraron datos conforme a los criterios de búsqueda");
|
||||
console.log(
|
||||
'No se encontraron datos conforme a los criterios de búsqueda',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) throw new Error("Error en la petición: " + response.statusText);
|
||||
if (!response.ok)
|
||||
throw new Error('Error en la petición: ' + response.statusText);
|
||||
|
||||
const json: DatosRespuesta[] = await response.json();
|
||||
|
||||
let nuevos = 0;
|
||||
let actualizados = 0;
|
||||
|
||||
let existe = await this.tipoUsuarioRepository.findOne({ where: { tipo_usuario: 'Profesor' } });
|
||||
let existe = await this.tipoUsuarioRepository.findOne({
|
||||
where: { tipo_usuario: 'Profesor' },
|
||||
});
|
||||
if (!existe) {
|
||||
const tipoUsuario = this.tipoUsuarioRepository.create({ tipo_usuario: 'Profesor' });
|
||||
const tipoUsuario = this.tipoUsuarioRepository.create({
|
||||
tipo_usuario: 'Profesor',
|
||||
});
|
||||
existe = await this.tipoUsuarioRepository.save(tipoUsuario);
|
||||
}
|
||||
|
||||
@@ -237,31 +224,40 @@ export class UsuariosService {
|
||||
|
||||
const existente = await this.usuarioRepository.findOne({
|
||||
where: { rfc: prof.rfc },
|
||||
relations: ['genero']
|
||||
relations: ['genero'],
|
||||
});
|
||||
|
||||
if (!existente) {
|
||||
let genero: Genero | null = null;
|
||||
if (prof.genero === 'M' || prof.genero === 'F') {
|
||||
const generoTexto = prof.genero === 'M' ? 'Masculino' : 'Femenino';
|
||||
genero = await this.generoRepository.findOne({ where: { genero: generoTexto } });
|
||||
const generoTexto =
|
||||
prof.genero === 'M' ? 'Masculino' : 'Femenino';
|
||||
genero = await this.generoRepository.findOne({
|
||||
where: { genero: generoTexto },
|
||||
});
|
||||
if (!genero) {
|
||||
genero = await this.generoRepository.create({ genero: generoTexto });
|
||||
genero = await this.generoRepository.create({
|
||||
genero: generoTexto,
|
||||
});
|
||||
await this.generoRepository.save(genero);
|
||||
}
|
||||
}
|
||||
|
||||
let carrera = await this.carreraRepository.findOne({ where: { carrera: prof.nombreCarrera.trim() } })
|
||||
let carrera = await this.carreraRepository.findOne({
|
||||
where: { carrera: prof.nombreCarrera.trim() },
|
||||
});
|
||||
|
||||
if (!carrera) {
|
||||
const nuevaCarrera = await this.carreraRepository.create({ carrera: prof.nombreCarrera.trim(), clave: '' });
|
||||
const nuevaCarrera = await this.carreraRepository.create({
|
||||
carrera: prof.nombreCarrera.trim(),
|
||||
clave: '',
|
||||
});
|
||||
carrera = await this.carreraRepository.save(nuevaCarrera);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const nuevo = await this.usuarioRepository.create({
|
||||
num_cuenta: prof.numeroTrabajador == '' ? undefined : prof.numeroTrabajador,
|
||||
num_cuenta:
|
||||
prof.numeroTrabajador == '' ? undefined : prof.numeroTrabajador,
|
||||
nombre: prof.nombre,
|
||||
a_paterno: prof.apellidoPaterno,
|
||||
a_materno: prof.apellidoMaterno,
|
||||
@@ -269,7 +265,7 @@ export class UsuariosService {
|
||||
fecha_nacimiento: prof.fechaNacimiento,
|
||||
genero,
|
||||
|
||||
movimiento: mov
|
||||
movimiento: mov,
|
||||
});
|
||||
|
||||
const savedUser = await this.usuarioRepository.save(nuevo);
|
||||
@@ -283,13 +279,19 @@ export class UsuariosService {
|
||||
AT: prof.numeroTrabajador !== '',
|
||||
Red: prof.numeroTrabajador !== '',
|
||||
Prestamos: prof.numeroTrabajador !== '',
|
||||
Correo: true
|
||||
Correo: true,
|
||||
});
|
||||
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
|
||||
const userCarrera = await this.carreraUsuario.create({ carrera, usuario: savedUser });
|
||||
const usuarioTipo = await this.usuarioTipoUsuario.create({ tipoUsuario: existe, usuario: savedUser });
|
||||
const userCarrera = await this.carreraUsuario.create({
|
||||
carrera,
|
||||
usuario: savedUser,
|
||||
});
|
||||
const usuarioTipo = await this.usuarioTipoUsuario.create({
|
||||
tipoUsuario: existe,
|
||||
usuario: savedUser,
|
||||
});
|
||||
|
||||
await this.carreraUsuario.save(userCarrera);
|
||||
await this.usuarioTipoUsuario.save(usuarioTipo);
|
||||
@@ -298,67 +300,75 @@ export class UsuariosService {
|
||||
} else {
|
||||
let cambios = false;
|
||||
|
||||
|
||||
if (existente.nombre !== prof.nombre) {
|
||||
existente.nombre = prof.nombre;
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
|
||||
if (servActivo) {
|
||||
servActivo.Red = true;
|
||||
servActivo.AT = true;
|
||||
servActivo.Prestamos = true;
|
||||
|
||||
|
||||
servActivo.ATStatus = 'Inactivo';
|
||||
servActivo.PrestamosStatus = 'Inactivo';
|
||||
servActivo.RedStatus = 'Inactivo';
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
cambios = true;
|
||||
}
|
||||
|
||||
if (existente.a_paterno !== prof.apellidoPaterno) {
|
||||
existente.a_paterno = prof.apellidoPaterno;
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
|
||||
if (servActivo) {
|
||||
servActivo.Red = true;
|
||||
servActivo.AT = true;
|
||||
servActivo.Prestamos = true;
|
||||
|
||||
|
||||
servActivo.ATStatus = 'Inactivo';
|
||||
servActivo.PrestamosStatus = 'Inactivo';
|
||||
servActivo.RedStatus = 'Inactivo';
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
|
||||
cambios = true;
|
||||
}
|
||||
|
||||
|
||||
if (existente.a_materno !== prof.apellidoMaterno) {
|
||||
|
||||
existente.a_materno = prof.apellidoMaterno;
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
|
||||
if (servActivo) {
|
||||
servActivo.Red = true;
|
||||
servActivo.AT = true;
|
||||
servActivo.Prestamos = true;
|
||||
|
||||
|
||||
servActivo.ATStatus = 'Inactivo';
|
||||
servActivo.PrestamosStatus = 'Inactivo';
|
||||
servActivo.RedStatus = 'Inactivo';
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
|
||||
cambios = true;
|
||||
@@ -366,31 +376,35 @@ export class UsuariosService {
|
||||
|
||||
if (existente.rfc !== prof.rfc) {
|
||||
existente.rfc = prof.rfc;
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
|
||||
if (servActivo) {
|
||||
servActivo.Red = true;
|
||||
|
||||
servActivo.Prestamos = true;
|
||||
|
||||
|
||||
servActivo.PrestamosStatus = 'Inactivo';
|
||||
servActivo.RedStatus = 'Inactivo';
|
||||
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
cambios = true;
|
||||
}
|
||||
|
||||
if (existente.fecha_nacimiento !== prof.fechaNacimiento) {
|
||||
existente.fecha_nacimiento = prof.fechaNacimiento;
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
|
||||
if (servActivo) {
|
||||
|
||||
|
||||
servActivo.Prestamos = true;
|
||||
servActivo.Correo = true;
|
||||
servActivo.PrestamosStatus = 'Inactivo';
|
||||
@@ -398,16 +412,23 @@ export class UsuariosService {
|
||||
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
cambios = true;
|
||||
}
|
||||
|
||||
if (prof.numeroTrabajador && existente.num_cuenta !== prof.numeroTrabajador) {
|
||||
if (
|
||||
prof.numeroTrabajador &&
|
||||
existente.num_cuenta !== prof.numeroTrabajador
|
||||
) {
|
||||
existente.num_cuenta = prof.numeroTrabajador;
|
||||
|
||||
|
||||
const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } });
|
||||
const servActivo = await this.servActivosRepository.findOne({
|
||||
where: { usuario: { id_usuario: existente.id_usuario } },
|
||||
});
|
||||
if (servActivo) {
|
||||
servActivo.Red = true;
|
||||
servActivo.AT = true;
|
||||
@@ -420,7 +441,10 @@ export class UsuariosService {
|
||||
servActivo.RedStatus = 'Inactivo';
|
||||
await this.servActivosRepository.save(servActivo);
|
||||
} else {
|
||||
console.warn('No se encontró el servicio activo para el usuario:', existente);
|
||||
console.warn(
|
||||
'No se encontró el servicio activo para el usuario:',
|
||||
existente,
|
||||
);
|
||||
}
|
||||
cambios = true;
|
||||
}
|
||||
@@ -433,36 +457,51 @@ export class UsuariosService {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Progreso -> Nuevos: ${nuevos}, Actualizados: ${actualizados}`);
|
||||
console.log(
|
||||
`Progreso -> Nuevos: ${nuevos}, Actualizados: ${actualizados}`,
|
||||
);
|
||||
} catch (innerError) {
|
||||
console.error('Error procesando profesor:', prof, innerError);
|
||||
}
|
||||
}
|
||||
this.movimientoService.updateStatus(mov.id_mov, 'SUCCESS', 'Carga masiva de web Service completa: ' + `Nuevos: ${nuevos}, Actualizados: ${actualizados}`)
|
||||
this.movimientoService.updateStatus(
|
||||
mov.id_mov,
|
||||
'SUCCESS',
|
||||
'Carga masiva de web Service completa: ' +
|
||||
`Nuevos: ${nuevos}, Actualizados: ${actualizados}`,
|
||||
);
|
||||
if (!process.env.EMAIL_USER) {
|
||||
throw new Error()
|
||||
throw new Error();
|
||||
}
|
||||
this.mailService.sendMail({
|
||||
to: process.env.EMAIL_USER,
|
||||
subject: 'Carga de datos exitosa',
|
||||
text: 'Carga masiva de web Service completa: ' + `Nuevos: ${nuevos}, Actualizados: ${actualizados}`,
|
||||
html: '<p></p>'
|
||||
})
|
||||
text:
|
||||
'Carga masiva de web Service completa: ' +
|
||||
`Nuevos: ${nuevos}, Actualizados: ${actualizados}`,
|
||||
html: '',
|
||||
});
|
||||
|
||||
this.excelService.enviarCargaMasiva();
|
||||
this.excelService.enviarCargaMasiva({ nuevos, actualizados });
|
||||
|
||||
return `Importación finalizada. Nuevos: ${nuevos}, Actualizados: ${actualizados}`;
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error('Error al consultar profesores desde el WebService', error);
|
||||
this.logger.error(
|
||||
'Error al consultar profesores desde el WebService',
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async cargaIndividual(usuario: CreateUsuarioDto, origen: string, user:string) {
|
||||
async cargaIndividual(
|
||||
usuario: CreateUsuarioDto,
|
||||
origen: string,
|
||||
user: string,
|
||||
) {
|
||||
console.log('Iniciando carga individual para usuario:', usuario);
|
||||
const queryRunner = this.usuarioRepository.manager.connection.createQueryRunner();
|
||||
const queryRunner =
|
||||
this.usuarioRepository.manager.connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
@@ -476,12 +515,20 @@ export class UsuariosService {
|
||||
throw new Error('Ya existe este usuario');
|
||||
}
|
||||
|
||||
const mov = await this.movimientoService.logger(queryRunner, origen, 'LOADING', 'la carga se hizo por: '+user , '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') {
|
||||
const generoTexto = usuario.genero === 'M' ? 'Masculino' : 'Femenino';
|
||||
genero = await queryRunner.manager.findOne(Genero, { where: { genero: generoTexto } });
|
||||
genero = await queryRunner.manager.findOne(Genero, {
|
||||
where: { genero: generoTexto },
|
||||
});
|
||||
if (!genero) {
|
||||
genero = queryRunner.manager.create(Genero, { genero: generoTexto });
|
||||
await queryRunner.manager.save(genero);
|
||||
@@ -489,24 +536,29 @@ export class UsuariosService {
|
||||
}
|
||||
|
||||
let carrera;
|
||||
if(usuario.carrera!=undefined){
|
||||
carrera = await queryRunner.manager.findOne(Carrera, { where: { carrera: usuario.carrera } });
|
||||
if (usuario.carrera != undefined) {
|
||||
carrera = await queryRunner.manager.findOne(Carrera, {
|
||||
where: { carrera: usuario.carrera },
|
||||
});
|
||||
|
||||
if (!carrera) {
|
||||
carrera= await queryRunner.manager.findOne(Carrera, {where:{carrera: ""}})
|
||||
carrera = await queryRunner.manager.findOne(Carrera, {
|
||||
where: { carrera: '' },
|
||||
});
|
||||
}
|
||||
console.log(carrera)
|
||||
}else{
|
||||
carrera= await queryRunner.manager.findOne(Carrera, {where:{carrera: ""}})
|
||||
if(!carrera){
|
||||
const nuevaCarrera = queryRunner.manager.create(Carrera, { carrera: "", clave: "" });
|
||||
console.log(carrera);
|
||||
} else {
|
||||
carrera = await queryRunner.manager.findOne(Carrera, {
|
||||
where: { carrera: '' },
|
||||
});
|
||||
if (!carrera) {
|
||||
const nuevaCarrera = queryRunner.manager.create(Carrera, {
|
||||
carrera: '',
|
||||
clave: '',
|
||||
});
|
||||
carrera = await queryRunner.manager.save(nuevaCarrera);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const nuevo = queryRunner.manager.create(Usuario, {
|
||||
num_cuenta: usuario.num_cuenta ?? usuario.usuario,
|
||||
@@ -521,21 +573,37 @@ export class UsuariosService {
|
||||
contraseña: usuario.contraseña ?? null, // Asegúrate de manejar la contraseña adecuadamente
|
||||
});
|
||||
|
||||
console.log(nuevo)
|
||||
console.log(nuevo);
|
||||
|
||||
const savedUser = await queryRunner.manager.save(nuevo);
|
||||
|
||||
const userCarrera = queryRunner.manager.create(CarreraUsuario, { carrera, usuario: savedUser });
|
||||
const userCarrera = queryRunner.manager.create(CarreraUsuario, {
|
||||
carrera,
|
||||
usuario: savedUser,
|
||||
});
|
||||
await queryRunner.manager.save(userCarrera);
|
||||
|
||||
const FieldMap = [
|
||||
'Diplomado', 'Extra Largo', 'Servicio Social', 'Idiomas R (UNAM)', 'Idiomas Sabatino',
|
||||
'Reinscrito', 'Posgrado', 'Intercambio UNAM', 'Movilidad', 'Ampliación de Conocimiento',
|
||||
'Licenciatura', 'Profesor', 'Trabajadores', 'Caso especial',
|
||||
'Diplomado',
|
||||
'Extra Largo',
|
||||
'Servicio Social',
|
||||
'Idiomas R (UNAM)',
|
||||
'Idiomas Sabatino',
|
||||
'Reinscrito',
|
||||
'Posgrado',
|
||||
'Intercambio UNAM',
|
||||
'Movilidad',
|
||||
'Ampliación de Conocimiento',
|
||||
'Licenciatura',
|
||||
'Profesor',
|
||||
'Trabajadores',
|
||||
'Caso especial',
|
||||
];
|
||||
|
||||
if (!FieldMap.includes(usuario.tipo_usuario)) {
|
||||
throw new Error(`Tipo de usuario no permitido: ${usuario.tipo_usuario}`);
|
||||
throw new Error(
|
||||
`Tipo de usuario no permitido: ${usuario.tipo_usuario}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Verifica si el tipo de usuario ya existe
|
||||
@@ -558,17 +626,13 @@ export class UsuariosService {
|
||||
});
|
||||
await queryRunner.manager.save(usuarioTipo);
|
||||
|
||||
|
||||
let at:boolean=false;
|
||||
let correo:boolean=false;
|
||||
let red:boolean=false;
|
||||
let solicita:boolean=false;
|
||||
|
||||
let at: boolean = false;
|
||||
let correo: boolean = false;
|
||||
let red: boolean = false;
|
||||
let solicita: boolean = false;
|
||||
|
||||
switch (usuario.tipo_usuario.trim()) {
|
||||
|
||||
case 'Diplomado':
|
||||
|
||||
const servActivosDiplomado = this.servActivosRepository.create({
|
||||
Correo: true,
|
||||
usuario: savedUser,
|
||||
@@ -577,7 +641,7 @@ export class UsuariosService {
|
||||
CorreoStatus: 'Inactivo',
|
||||
PrestamosStatus: 'Inactivo',
|
||||
});
|
||||
correo=true;
|
||||
correo = true;
|
||||
await queryRunner.manager.save(servActivosDiplomado);
|
||||
break;
|
||||
|
||||
@@ -590,10 +654,9 @@ export class UsuariosService {
|
||||
ATStatus: 'Inactivo',
|
||||
CorreoStatus: 'Inactivo',
|
||||
PrestamosStatus: 'Inactivo',
|
||||
|
||||
});
|
||||
solicita=true;
|
||||
correo=true;
|
||||
solicita = true;
|
||||
correo = true;
|
||||
await queryRunner.manager.save(servActivosExtraLargo);
|
||||
break;
|
||||
|
||||
@@ -608,14 +671,12 @@ export class UsuariosService {
|
||||
CorreoStatus: 'Inactivo',
|
||||
PrestamosStatus: 'Inactivo',
|
||||
});
|
||||
at=true;
|
||||
red=true;
|
||||
correo=true;
|
||||
at = true;
|
||||
red = true;
|
||||
correo = true;
|
||||
await queryRunner.manager.save(servActivosServicio);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case 'Idiomas R (UNAM)':
|
||||
case 'Idiomas Sabatino':
|
||||
const servActivosIdiomas = this.servActivosRepository.create({
|
||||
@@ -627,15 +688,12 @@ export class UsuariosService {
|
||||
CorreoStatus: 'Inactivo',
|
||||
PrestamosStatus: 'Inactivo',
|
||||
});
|
||||
red=true;
|
||||
correo=true;
|
||||
red = true;
|
||||
correo = true;
|
||||
await queryRunner.manager.save(servActivosIdiomas);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'Reinscrito':
|
||||
case 'Posgrado':
|
||||
case 'Intercambio UNAM':
|
||||
@@ -644,7 +702,6 @@ export class UsuariosService {
|
||||
case 'Licenciatura':
|
||||
case 'Profesor':
|
||||
const servActivos = this.servActivosRepository.create({
|
||||
|
||||
Red: true,
|
||||
AT: true,
|
||||
Correo: true,
|
||||
@@ -655,43 +712,35 @@ export class UsuariosService {
|
||||
CorreoStatus: 'Inactivo',
|
||||
PrestamosStatus: 'Inactivo',
|
||||
});
|
||||
at=true;
|
||||
red=true;
|
||||
correo=true;
|
||||
solicita=true;
|
||||
at = true;
|
||||
red = true;
|
||||
correo = true;
|
||||
solicita = true;
|
||||
await queryRunner.manager.save(servActivos);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'Caso especial':
|
||||
case 'Trabajadores':
|
||||
const servActivosTrabajadores = this.servActivosRepository.create({
|
||||
Red: true,
|
||||
usuario: savedUser,
|
||||
RedStatus: 'Inactivo',
|
||||
|
||||
});
|
||||
red=true;
|
||||
red = true;
|
||||
await queryRunner.manager.save(servActivosTrabajadores);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
console.log(savedUser)
|
||||
console.log(savedUser);
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
|
||||
|
||||
return { saved: savedUser, movId: mov.id_mov, at, correo, red, solicita };
|
||||
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw new Error("Error en la carga individual: " + error.message);
|
||||
throw new Error('Error en la carga individual: ' + error.message);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user