carga masiva usuarios listo
This commit is contained in:
parent
23755c50bf
commit
aa7ee5fdd3
@ -1,9 +1,6 @@
|
|||||||
import * as fs from 'fs';
|
|
||||||
import * as csvtojson from 'csvtojson';
|
import * as csvtojson from 'csvtojson';
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
import { Equipo } from '../equipo/entity/equipo.entity';
|
||||||
import { InstitucionCarrera } from '../institucion-carrera/entity/institucion-carrera.entity';
|
|
||||||
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
|
||||||
import { Usuario } from '../usuario/entity/usuario.entity';
|
import { Usuario } from '../usuario/entity/usuario.entity';
|
||||||
import { CarritoService } from '../carrito/carrito.service';
|
import { CarritoService } from '../carrito/carrito.service';
|
||||||
import { EquipoService } from '../equipo/equipo.service';
|
import { EquipoService } from '../equipo/equipo.service';
|
||||||
@ -16,7 +13,6 @@ import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
|||||||
import { UsuarioService } from '../usuario/usuario.service';
|
import { UsuarioService } from '../usuario/usuario.service';
|
||||||
import { UploadFileCargaMasivaUsuarioDto } from './dto/upload-file-carga-masiva-usuario.dto';
|
import { UploadFileCargaMasivaUsuarioDto } from './dto/upload-file-carga-masiva-usuario.dto';
|
||||||
import { UploadFileCargaMasivaEquipoDto } from './dto/upload-file-carga-masiva-equipo.dto';
|
import { UploadFileCargaMasivaEquipoDto } from './dto/upload-file-carga-masiva-equipo.dto';
|
||||||
import { Equipo } from '../equipo/entity/equipo.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UploadFileService {
|
export class UploadFileService {
|
||||||
@ -115,17 +111,19 @@ export class UploadFileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (equipo) {
|
if (equipo) {
|
||||||
// if (
|
if (
|
||||||
// equipo.numero_inventario != equipos[i].numero_inventario ||
|
equipo.numero_inventario != equipos[i].numero_inventario ||
|
||||||
// equipo.numero_serie != equipos[i].numero_serie
|
equipo.numero_serie != equipos[i].numero_serie ||
|
||||||
// ) {
|
(equipo.numero_inventario == equipos[i].numero_inventario &&
|
||||||
// if (equipo.numero_inventario != equipos[i].numero_inventario)
|
equipo.numero_serie != equipos[i].numero_serie)
|
||||||
// error += ' ';
|
) {
|
||||||
// if (error != this.errorBase(i)) error += ',';
|
if (equipo.numero_inventario != equipos[i].numero_inventario)
|
||||||
// if (equipo.numero_serie != equipos[i].numero_serie)
|
error += ' ';
|
||||||
// errores.push(error + '.');
|
if (error != this.errorBase(i)) error += ',';
|
||||||
// continue;
|
if (equipo.numero_serie != equipos[i].numero_serie)
|
||||||
// }
|
errores.push(error + '.');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
equipo = await this.equipoService.findByNumeroInventario(
|
equipo = await this.equipoService.findByNumeroInventario(
|
||||||
institucion,
|
institucion,
|
||||||
@ -145,9 +143,7 @@ export class UploadFileService {
|
|||||||
equipos[i].numero_inventario,
|
equipos[i].numero_inventario,
|
||||||
equipos[i].numero_serie,
|
equipos[i].numero_serie,
|
||||||
)
|
)
|
||||||
.then((equipo) => {
|
.then((equipo) => equiposNuevos.push(equipo));
|
||||||
equiposNuevos.push(equipo);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -208,10 +204,11 @@ export class UploadFileService {
|
|||||||
);
|
);
|
||||||
const carrera =
|
const carrera =
|
||||||
tipoUsuario &&
|
tipoUsuario &&
|
||||||
usuarios[i].carrera &&
|
(tipoUsuario.id_tipo_usuario === 5 || usuarios[i].carrera)
|
||||||
tipoUsuario.id_tipo_usuario > 5
|
|
||||||
? await this.institucionCarreraService.findCarreraByCarrera(
|
? await this.institucionCarreraService.findCarreraByCarrera(
|
||||||
usuarios[i].carrera,
|
tipoUsuario.id_tipo_usuario === 5
|
||||||
|
? 'PROFESOR'
|
||||||
|
: usuarios[i].carrera,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
@ -225,14 +222,13 @@ export class UploadFileService {
|
|||||||
if (
|
if (
|
||||||
!tipoUsuario ||
|
!tipoUsuario ||
|
||||||
tipoUsuario.id_tipo_usuario < 5 ||
|
tipoUsuario.id_tipo_usuario < 5 ||
|
||||||
(!carrera && tipoUsuario.id_tipo_usuario < 6) ||
|
!carrera ||
|
||||||
(carrera && !institucionCarrera)
|
(carrera && !institucionCarrera)
|
||||||
) {
|
) {
|
||||||
if (!tipoUsuario) error += ' no existe este tipo de usuario.';
|
if (!tipoUsuario) error += ' no existe este tipo de usuario.';
|
||||||
if (tipoUsuario.id_tipo_usuario < 5)
|
if (tipoUsuario.id_tipo_usuario < 5)
|
||||||
' no se puede asignar este tipo de usuario a este usuario.';
|
' no se puede asignar este tipo de usuario a este usuario.';
|
||||||
if (!carrera && tipoUsuario.id_tipo_usuario < 6)
|
if (!carrera) error += ' falta del campo carrera para el alumno.';
|
||||||
error += ' falta del campo carrera para el alumno.';
|
|
||||||
if (carrera && !institucionCarrera)
|
if (carrera && !institucionCarrera)
|
||||||
error += ' la carrera no pertenece a la institución.';
|
error += ' la carrera no pertenece a la institución.';
|
||||||
errores.push(error);
|
errores.push(error);
|
||||||
@ -251,7 +247,7 @@ export class UploadFileService {
|
|||||||
)
|
)
|
||||||
usuario.institucionCarrera = institucionCarrera;
|
usuario.institucionCarrera = institucionCarrera;
|
||||||
await this.usuarioService
|
await this.usuarioService
|
||||||
.update(usuario)
|
.update(usuario, false)
|
||||||
.then(({ message }) => mensajes.push(message));
|
.then(({ message }) => mensajes.push(message));
|
||||||
} else
|
} else
|
||||||
await this.usuarioService
|
await this.usuarioService
|
||||||
@ -262,7 +258,7 @@ export class UploadFileService {
|
|||||||
].apellido_m.trim()} ${usuarios[i].nombres.trim()}`,
|
].apellido_m.trim()} ${usuarios[i].nombres.trim()}`,
|
||||||
institucion,
|
institucion,
|
||||||
tipoUsuario,
|
tipoUsuario,
|
||||||
institucionCarrera ? institucionCarrera : null,
|
institucionCarrera,
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
usuariosNuevos.push(res.usuario);
|
usuariosNuevos.push(res.usuario);
|
||||||
@ -284,7 +280,9 @@ export class UploadFileService {
|
|||||||
downloadLogo(id_institucion: number) {}
|
downloadLogo(id_institucion: number) {}
|
||||||
|
|
||||||
errorBase(index) {
|
errorBase(index) {
|
||||||
return `Se salto la linea ${index + 2} por:`;
|
return `Se saltó la linea ${
|
||||||
|
index + 2
|
||||||
|
} por el siguiente/los siguientes motivos(s):`;
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadLogo(file: Express.Multer.File, id_institucion: number) {}
|
uploadLogo(file: Express.Multer.File, id_institucion: number) {}
|
||||||
|
@ -34,17 +34,16 @@ export class UsuarioService {
|
|||||||
nombre: string,
|
nombre: string,
|
||||||
institucion: Institucion,
|
institucion: Institucion,
|
||||||
tipoUsuario: TipoUsuario,
|
tipoUsuario: TipoUsuario,
|
||||||
institucionCarrera?: InstitucionCarrera,
|
institucionCarrera: InstitucionCarrera,
|
||||||
) {
|
) {
|
||||||
const data: {
|
const data: {
|
||||||
carrera?: InstitucionCarrera;
|
institucionCarrera: InstitucionCarrera;
|
||||||
institucion: Institucion;
|
institucion: Institucion;
|
||||||
nombre: string;
|
nombre: string;
|
||||||
tipoUsuario: TipoUsuario;
|
tipoUsuario: TipoUsuario;
|
||||||
usuario: string;
|
usuario: string;
|
||||||
} = { institucion, nombre, tipoUsuario, usuario };
|
} = { institucion, nombre, tipoUsuario, usuario, institucionCarrera };
|
||||||
|
|
||||||
if (institucionCarrera) data.carrera = institucionCarrera;
|
|
||||||
return this.repository
|
return this.repository
|
||||||
.save(this.repository.create(data))
|
.save(this.repository.create(data))
|
||||||
.then((usuario) => ({
|
.then((usuario) => ({
|
||||||
@ -227,8 +226,8 @@ export class UsuarioService {
|
|||||||
.then((_) => ({ message: 'Se registró correctamente un usuario.' }));
|
.then((_) => ({ message: 'Se registró correctamente un usuario.' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
update(attrs: Partial<Usuario>) {
|
update(attrs: Partial<Usuario>, validarPassword = true) {
|
||||||
return this.findById(attrs.id_usuario, true, true)
|
return this.findById(attrs.id_usuario, true, validarPassword)
|
||||||
.then((usuario) => {
|
.then((usuario) => {
|
||||||
Object.assign(usuario, attrs);
|
Object.assign(usuario, attrs);
|
||||||
return this.repository.save(usuario);
|
return this.repository.save(usuario);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
numero_cuenta,nombres,apellido_p,apellido_m,carrra,tipo_usuario
|
numero_cuenta,nombres,apellido_p,apellido_m,carrera,tipo_usuario
|
||||||
313144567,Nombre 1,Apellido_p 1,Apellido_m 1,Carrera,Alumno
|
313144567,Nombre 1,Apellido_p 1,Apellido_m 1,MATEMATICAS APLICADAS Y COMPUTACION,Alumno
|
||||||
415895839,Nombre 2,Apellido_p 2,Apellido_m 2,Posgrado,Posgrado
|
415895839,Nombre 2,Apellido_p 2,Apellido_m 2,MEDICINA VETERINARIA Y ZOOTECNIA,Posgrado
|
||||||
813573,Nombre 3,Apellido_p 3,Apellido_m 3,,Profesor
|
813573,Nombre 3,Apellido_p 3,Apellido_m 3,,Profesor
|
|
Loading…
Reference in New Issue
Block a user