se junto el modulo carrera con institucion carrera y se exporto el servicio carrito
This commit is contained in:
+2
-4
@@ -5,7 +5,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { BcryptModule } from './bcrypt/bcrypt.module';
|
||||
import { CarreraModule } from './carrera/carrera.module';
|
||||
import { CarreraProgramaModule } from './carrera-programa/carrera-programa.module';
|
||||
import { CarritoModule } from './carrito/carrito.module';
|
||||
import { CronModule } from './cron/cron.module';
|
||||
@@ -31,7 +30,7 @@ import { TipoUsuarioModule } from './tipo-usuario/tipo-usuario.module';
|
||||
import { UploadFileModule } from './upload-file/upload-file.module';
|
||||
import { UsuarioModule } from './usuario/usuario.module';
|
||||
|
||||
import { Carrera } from './carrera/entity/carrera.entity';
|
||||
import { Carrera } from './institucion-carrera/entity/carrera.entity';
|
||||
import { CarreraPrograma } from './carrera-programa/entity/carrera-programa.entity';
|
||||
import { Carrito } from './carrito/entity/carrito.entity';
|
||||
import { Dia } from './institucion-dia/entity/dia.entity';
|
||||
@@ -50,7 +49,7 @@ import { InstitucionTipoEntrada } from './institucion-tipo-entrada/entity/instit
|
||||
import { Modulo } from './modulo/entity/modulo.entity';
|
||||
import { Motivo } from './motivo/entity/motivo.entity';
|
||||
import { Multa } from './multa/entity/multa.entity';
|
||||
import { Nivel } from './carrera/entity/nivel.entity';
|
||||
import { Nivel } from './institucion-carrera/entity/nivel.entity';
|
||||
import { Operador } from './operador/entity/operador.entity';
|
||||
import { Prestamo } from './prestamo/entity/prestamo.entity';
|
||||
import { Programa } from './programa/entity/programa.entity';
|
||||
@@ -110,7 +109,6 @@ import { SoapClientModule } from './soap-client/soap-client.module';
|
||||
}),
|
||||
AuthModule,
|
||||
BcryptModule,
|
||||
CarreraModule,
|
||||
CarreraProgramaModule,
|
||||
CarritoModule,
|
||||
CronModule,
|
||||
|
||||
@@ -3,13 +3,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CarreraProgramaController } from './carrera-programa.controller';
|
||||
import { CarreraProgramaService } from './carrera-programa.service';
|
||||
import { CarreraPrograma } from './entity/carrera-programa.entity';
|
||||
import { CarreraModule } from '../carrera/carrera.module';
|
||||
import { InstitucionCarreraModule } from '../institucion-carrera/institucion-carrera.module';
|
||||
import { ProgramaModule } from '../programa/programa.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CarreraModule,
|
||||
InstitucionCarreraModule,
|
||||
TypeOrmModule.forFeature([CarreraPrograma]),
|
||||
ProgramaModule,
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CarreraPrograma } from './entity/carrera-programa.entity';
|
||||
import { CarreraService } from '../carrera/carrera.service';
|
||||
import { InstitucionCarreraService } from '../institucion-carrera/institucion-carrera.service';
|
||||
import { ProgramaService } from '../programa/programa.service';
|
||||
|
||||
@@ -15,7 +14,6 @@ export class CarreraProgramaService {
|
||||
constructor(
|
||||
@InjectRepository(CarreraPrograma)
|
||||
private repository: Repository<CarreraPrograma>,
|
||||
private carreraService: CarreraService,
|
||||
private institucionCarreraService: InstitucionCarreraService,
|
||||
private programaService: ProgramaService,
|
||||
) {}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CarreraController } from './carrera.controller';
|
||||
|
||||
describe('CarreraController', () => {
|
||||
let controller: CarreraController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CarreraController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CarreraController>(CarreraController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { CarreraService } from './carrera.service';
|
||||
|
||||
@Controller('carrera')
|
||||
@ApiTags('carrera')
|
||||
export class CarreraController {
|
||||
constructor(private carreraService: CarreraService) {}
|
||||
|
||||
@Get()
|
||||
get() {
|
||||
return this.carreraService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CarreraController } from './carrera.controller';
|
||||
import { CarreraService } from './carrera.service';
|
||||
import { Carrera } from './entity/carrera.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Carrera])],
|
||||
controllers: [CarreraController],
|
||||
providers: [CarreraService],
|
||||
exports: [CarreraService],
|
||||
})
|
||||
export class CarreraModule {}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CarreraService } from './carrera.service';
|
||||
|
||||
describe('CarreraService', () => {
|
||||
let service: CarreraService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CarreraService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CarreraService>(CarreraService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Carrera } from './entity/carrera.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CarreraService {
|
||||
constructor(
|
||||
@InjectRepository(Carrera) private repository: Repository<Carrera>,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.repository.find();
|
||||
}
|
||||
|
||||
findById(id_carrera: number) {
|
||||
return this.repository.findOne({ id_carrera }).then((carrera) => {
|
||||
if (!carrera) throw new NotFoundException('No existe esta carrera.');
|
||||
return carrera;
|
||||
});
|
||||
}
|
||||
|
||||
findByCarrera(carrera: string, validarNoExiste = true) {
|
||||
return this.repository.findOne({ carrera }).then((carrera) => {
|
||||
if (validarNoExiste && !carrera)
|
||||
throw new NotFoundException('No existe esta carrera.');
|
||||
return carrera;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,6 @@ import { ModuloModule } from '../modulo/modulo.module';
|
||||
],
|
||||
controllers: [CarritoController],
|
||||
providers: [CarritoService],
|
||||
exports: [CarritoService],
|
||||
})
|
||||
export class CarritoModule {}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import {
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { InstitucionCarrera } from '../../institucion-carrera/entity/institucion-carrera.entity';
|
||||
import { InstitucionCarrera } from './institucion-carrera.entity';
|
||||
import { Nivel } from './nivel.entity';
|
||||
|
||||
@Entity()
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Carrera } from '../../carrera/entity/carrera.entity';
|
||||
import { Carrera } from './carrera.entity';
|
||||
import { CarreraPrograma } from '../../carrera-programa/entity/carrera-programa.entity';
|
||||
import { Institucion } from '../../institucion/entity/institucion.entity';
|
||||
import { Usuario } from '../../usuario/entity/usuario.entity';
|
||||
|
||||
@@ -2,16 +2,15 @@ import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { InstitucionCarreraController } from './institucion-carrera.controller';
|
||||
import { InstitucionCarreraService } from './institucion-carrera.service';
|
||||
import { Carrera } from './entity/carrera.entity';
|
||||
import { InstitucionCarrera } from './entity/institucion-carrera.entity';
|
||||
import { Nivel } from '../carrera/entity/nivel.entity';
|
||||
import { Nivel } from './entity/nivel.entity';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { CarreraModule } from '../carrera/carrera.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CarreraModule,
|
||||
InstitucionModule,
|
||||
TypeOrmModule.forFeature([InstitucionCarrera, Nivel]),
|
||||
TypeOrmModule.forFeature([Carrera, InstitucionCarrera, Nivel]),
|
||||
],
|
||||
controllers: [InstitucionCarreraController],
|
||||
providers: [InstitucionCarreraService],
|
||||
|
||||
@@ -1,29 +1,51 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Carrera } from 'src/carrera/entity/carrera.entity';
|
||||
import { Institucion } from 'src/institucion/entity/institucion.entity';
|
||||
import { Carrera } from '../institucion-carrera/entity/carrera.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionCarrera } from './entity/institucion-carrera.entity';
|
||||
import { CarreraService } from '../carrera/carrera.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { Nivel } from './entity/nivel.entity';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionCarreraService {
|
||||
constructor(
|
||||
@InjectRepository(InstitucionCarrera)
|
||||
private repository: Repository<InstitucionCarrera>,
|
||||
private carreraService: CarreraService,
|
||||
private institucionCarreraRepository: Repository<InstitucionCarrera>,
|
||||
@InjectRepository(Carrera) private carreraRepository: Repository<Carrera>,
|
||||
@InjectRepository(Carrera) private nivelRepository: Repository<Nivel>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
findAllCarreras() {
|
||||
return this.carreraRepository.find();
|
||||
}
|
||||
|
||||
findCarreraByIdCarrera(id_carrera: number) {
|
||||
return this.carreraRepository.findOne({ id_carrera }).then((carrera) => {
|
||||
if (!carrera) throw new NotFoundException('No existe esta carrera.');
|
||||
return carrera;
|
||||
});
|
||||
}
|
||||
|
||||
findCarreraByCarrera(carrera: string, validarNoExiste = true) {
|
||||
return this.carreraRepository.findOne({ carrera }).then((carrera) => {
|
||||
if (validarNoExiste && !carrera)
|
||||
throw new NotFoundException('No existe esta carrera.');
|
||||
return carrera;
|
||||
});
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) => this.repository.find({ institucion }));
|
||||
.then((institucion) =>
|
||||
this.institucionCarreraRepository.find({ institucion }),
|
||||
);
|
||||
}
|
||||
|
||||
findById(id_institucion_carrera: number) {
|
||||
return this.repository
|
||||
return this.institucionCarreraRepository
|
||||
.findOne({ id_institucion_carrera })
|
||||
.then((institucionCarrera) => {
|
||||
if (!institucionCarrera)
|
||||
@@ -42,9 +64,9 @@ export class InstitucionCarreraService {
|
||||
: id_institucion;
|
||||
const carrera =
|
||||
typeof id_carrera === 'number'
|
||||
? await this.institucionService.findById(id_carrera)
|
||||
? await this.findCarreraByIdCarrera(id_carrera)
|
||||
: id_carrera;
|
||||
|
||||
return this.repository.findOne({ carrera, institucion });
|
||||
return this.institucionCarreraRepository.findOne({ carrera, institucion });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PrestamoController } from './prestamo.controller';
|
||||
import { PrestamoService } from './prestamo.service';
|
||||
import { Prestamo } from './entity/prestamo.entity';
|
||||
import { CarreraModule } from '../carrera/carrera.module';
|
||||
import { CarritoModule } from '../carrito/carrito.module';
|
||||
import { EquipoModule } from '../equipo/equipo.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Carrera } from '../carrera/entity/carrera.entity';
|
||||
import { Carrera } from '../institucion-carrera/entity/carrera.entity';
|
||||
import { Carrito } from '../carrito/entity/carrito.entity';
|
||||
import { Equipo } from '../equipo/entity/equipo.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
@@ -10,7 +10,6 @@ import { Prestamo } from './entity/prestamo.entity';
|
||||
import { TipoCarrito } from '../institucion-tipo-carrito/entity/tipo-carrito.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
||||
import { Usuario } from '../usuario/entity/usuario.entity';
|
||||
// import { CarreraService } from '../carrera/carrera.service';
|
||||
// import { CarritoService } from '../carrito/carrito.service';
|
||||
// import { EquipoService } from '../equipo/equipo.service';
|
||||
// import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@@ -2,16 +2,17 @@ import { ConflictException, Module } from '@nestjs/common';
|
||||
import { MulterModule } from '@nestjs/platform-express';
|
||||
import { UploadFileController } from './upload-file.controller';
|
||||
import { UploadFileService } from './upload-file.service';
|
||||
import { CarreraModule } from '../carrera/carrera.module';
|
||||
import { EquipoModule } from '../equipo/equipo.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { InstitucionCarreraModule } from '../institucion-carrera/institucion-carrera.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
import { UsuarioModule } from '../usuario/usuario.module';
|
||||
import { ProgramaModule } from '../programa/programa.module';
|
||||
import { CarritoModule } from '../carrito/carrito.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CarreraModule,
|
||||
CarritoModule,
|
||||
EquipoModule,
|
||||
InstitucionModule,
|
||||
InstitucionCarreraModule,
|
||||
@@ -26,6 +27,7 @@ import { UsuarioModule } from '../usuario/usuario.module';
|
||||
return cb(null, true);
|
||||
},
|
||||
}),
|
||||
ProgramaModule,
|
||||
TipoUsuarioModule,
|
||||
UsuarioModule,
|
||||
],
|
||||
|
||||
@@ -4,72 +4,81 @@ import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionCarrera } from 'src/institucion-carrera/entity/institucion-carrera.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
||||
import { CarreraService } from '../carrera/carrera.service';
|
||||
import { EquipoService } from '../equipo/equipo.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { InstitucionCarreraService } from '../institucion-carrera/institucion-carrera.service';
|
||||
import { CarritoService } from '../carrito/carrito.service'
|
||||
import { CarritoService } from '../carrito/carrito.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
import { UsuarioService } from '../usuario/usuario.service';
|
||||
import { ProgramaService } from '../programa/programa.service'
|
||||
import { ProgramaService } from '../programa/programa.service';
|
||||
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';
|
||||
|
||||
@Injectable()
|
||||
export class UploadFileService {
|
||||
constructor(
|
||||
private carreraService: CarreraService,
|
||||
private equipoService: EquipoService,
|
||||
private institucionService: InstitucionService,
|
||||
private institucionCarreraService: InstitucionCarreraService,
|
||||
private carritoService: CarritoService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
private usuarioService: UsuarioService,
|
||||
private programaService: ProgramaService
|
||||
private programaService: ProgramaService,
|
||||
) {}
|
||||
//programa y status
|
||||
async createEquipos(file: Express.Multer.File, id_carrito: number, id_programa: number, id_status: number) {
|
||||
const path = `${file.destination}/${file.fieldname}`
|
||||
const carrito = await this.carreraService.findById(id_carrito)
|
||||
const errores: string[] = []
|
||||
//programa y status
|
||||
async createEquipos(
|
||||
file: Express.Multer.File,
|
||||
id_carrito: number,
|
||||
id_programa: number,
|
||||
id_status: number,
|
||||
) {
|
||||
const path = `${file.destination}/${file.fieldname}`;
|
||||
const carrito = await this.carritoService.findById(id_carrito);
|
||||
const errores: string[] = [];
|
||||
|
||||
if (!file) throw new BadRequestException('No se mando el archivo de equipos.')
|
||||
if (!file)
|
||||
throw new BadRequestException('No se mando el archivo de equipos.');
|
||||
return csvtojson()
|
||||
.fromFile(path)
|
||||
.then(async (equipos: [UploadFileCargaMasivaEquipoDto]) => {
|
||||
for (let i = 0; i < equipos.length; i++) {
|
||||
let error = this.errorBase(i)
|
||||
let error = this.errorBase(i);
|
||||
|
||||
if(!equipos[i].modulo ||
|
||||
if (
|
||||
!equipos[i].modulo ||
|
||||
!equipos[i].carrito ||
|
||||
!equipos[i].tipo ||
|
||||
!equipos[i].equipo ||
|
||||
!equipos[i].numero_inventario ||
|
||||
!equipos[i].numero_serie ||
|
||||
!equipos[i].entradas ||
|
||||
!equipos[i].programas) {
|
||||
if (!equipos[i].modulo)
|
||||
error += 'falta el campo de modulo'
|
||||
!equipos[i].programas
|
||||
) {
|
||||
if (!equipos[i].modulo) error += 'falta el campo de modulo';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].carrito)
|
||||
error += ' falta del campo carrito';
|
||||
if (!equipos[i].carrito) error += ' falta del campo carrito';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].tipo) error += ' falta del campo tipo (tipo de equipo)';
|
||||
if (!equipos[i].tipo)
|
||||
error += ' falta del campo tipo (tipo de equipo)';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].equipo) error += ' falta del campo equipo';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].numero_inventario) error += ' falta del campo número de inventario';
|
||||
if (!equipos[i].numero_inventario)
|
||||
error += ' falta del campo número de inventario';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].numero_serie) error += ' falta del campo número de serie';
|
||||
if (!equipos[i].numero_serie)
|
||||
error += ' falta del campo número de serie';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!equipos[i].entradas) error += ' falta del campo entradas';
|
||||
errores.push(`${error}.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const programa = await this.programaService.findByPrograma(equipos[i].programas)
|
||||
const programa = await this.programaService.findByPrograma(
|
||||
equipos[i].programas,
|
||||
);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async createUsuarios(file: Express.Multer.File, id_institucion: number) {
|
||||
@@ -119,7 +128,7 @@ export class UploadFileService {
|
||||
tipoUsuario &&
|
||||
usuarios[i].carrera &&
|
||||
tipoUsuario.id_tipo_usuario > 5
|
||||
? await this.carreraService.findByCarrera(
|
||||
? await this.institucionCarreraService.findCarreraByCarrera(
|
||||
usuarios[i].carrera,
|
||||
false,
|
||||
)
|
||||
@@ -152,7 +161,9 @@ export class UploadFileService {
|
||||
usuario.tipoUsuario = tipoUsuario;
|
||||
usuario.activo = true;
|
||||
if (institucionCarrera) usuario.carrera = institucionCarrera;
|
||||
await this.usuarioService.update(usuario).then((usuarioUpdated) => {});
|
||||
await this.usuarioService
|
||||
.update(usuario)
|
||||
.then((usuarioUpdated) => {});
|
||||
} else
|
||||
await this.usuarioService
|
||||
.create(
|
||||
|
||||
Reference in New Issue
Block a user