se corrigieron los modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { JwtModule, JwtService } from '@nestjs/jwt';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { Usuario } from 'src/usuario/entities/usuario.entity';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Carrera } from './entities/carrera.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [],
|
||||
providers: [],
|
||||
exports: [],
|
||||
imports: [TypeOrmModule.forFeature([Carrera])],
|
||||
exports: [TypeOrmModule],
|
||||
})
|
||||
export class CarreraModule {}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { CreateCasoEspecialDto } from './dto/create-caso-especial.dto';
|
||||
import { UpdateCasoEspecialDto } from './dto/update-caso-especial.dto';
|
||||
import { ValidacionService } from 'src/helpers.services/validacion.service';
|
||||
@@ -12,6 +16,7 @@ import { DriveService } from 'src/drive/drive.service';
|
||||
import { Status } from 'src/status/entities/status.entity';
|
||||
import { FilterCasoEspecialDto } from './dto/filter-caso-especial.dto';
|
||||
import { arch } from 'os';
|
||||
import { SendMailDto } from 'src/helpers.services/dto/send-email.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CasoEspecialService {
|
||||
@@ -27,9 +32,7 @@ export class CasoEspecialService {
|
||||
private validacion: ValidacionService,
|
||||
private gmail: gmail,
|
||||
private drive: DriveService,
|
||||
) { }
|
||||
|
||||
|
||||
) {}
|
||||
|
||||
async create(body: CreateCasoEspecialDto, file: string) {
|
||||
const {
|
||||
@@ -49,49 +52,63 @@ export class CasoEspecialService {
|
||||
motivo = '',
|
||||
} = body;
|
||||
|
||||
const usuario = await this.usuarioRepository.findOneBy({ idUsuario: idUsuario });
|
||||
if (!usuario) throw new NotFoundException('Este alumno no existe en la db.');
|
||||
if (usuario.tipoUsuario.idTipoUsuario !== 3) throw new BadRequestException('Este usuario no es de tipo Alumno.');
|
||||
const usuario = await this.usuarioRepository.findOneBy({
|
||||
idUsuario: idUsuario,
|
||||
});
|
||||
if (!usuario)
|
||||
throw new NotFoundException('Este alumno no existe en la db.');
|
||||
if (usuario.tipoUsuario.idTipoUsuario !== 3)
|
||||
throw new BadRequestException('Este usuario no es de tipo Alumno.');
|
||||
|
||||
const carrera = await this.carreraRepository.findOneBy({ idCarrera: idCarrera });
|
||||
if (!carrera) throw new NotFoundException('Esta carrera no existe en la db.');
|
||||
const carrera = await this.carreraRepository.findOneBy({
|
||||
idCarrera: idCarrera,
|
||||
});
|
||||
if (!carrera)
|
||||
throw new NotFoundException('Esta carrera no existe en la db.');
|
||||
|
||||
const casoExistente = await this.casoEspecialRepository.findOne({ where: { usuario: usuario } });
|
||||
if (casoExistente) throw new BadRequestException('Este alumno ya tiene un Caso Especial.');
|
||||
const casoExistente = await this.casoEspecialRepository.findOne({
|
||||
where: { usuario: usuario },
|
||||
});
|
||||
if (casoExistente)
|
||||
throw new BadRequestException('Este alumno ya tiene un Caso Especial.');
|
||||
|
||||
const path = `./server/uploads/${file}`;
|
||||
const carpeta = await this.drive.folder(numeroCuenta);
|
||||
if (!carpeta) {
|
||||
throw new Error('No se pudo crear la carpeta en Drive.');
|
||||
}
|
||||
const archivoZip = await this.drive.uploadFile(path, `archivos.zip`, 'application/zip', carpeta);
|
||||
|
||||
const status = await this.statusRepository.findOne({ where: { idStatus: idStatus } })
|
||||
const archivoZip = await this.drive.uploadFile(
|
||||
path,
|
||||
`archivos.zip`,
|
||||
'application/zip',
|
||||
carpeta,
|
||||
);
|
||||
|
||||
const status = await this.statusRepository.findOne({
|
||||
where: { idStatus: idStatus },
|
||||
});
|
||||
|
||||
if (!status) throw new NotFoundException('Este status no existe en la db.');
|
||||
if(archivoZip === null) throw new Error('No se pudo subir el archivo a Drive.')
|
||||
|
||||
if (archivoZip === null)
|
||||
throw new Error('No se pudo subir el archivo a Drive.');
|
||||
|
||||
const nuevoCaso = this.casoEspecialRepository.create(
|
||||
{
|
||||
correo: correo,
|
||||
telefono: telefono,
|
||||
institucion: institucion,
|
||||
dependencia: dependencia,
|
||||
motivo: motivo,
|
||||
direccion: direccion,
|
||||
fechaInicio: fechaInicio,
|
||||
fechaFin: fechaFin,
|
||||
fechaNacimiento: fechaNacimiento,
|
||||
carpeta: carpeta,
|
||||
archivoZip: archivoZip,
|
||||
usuario: usuario,
|
||||
carrera: carrera,
|
||||
status: status,
|
||||
creditos: creditos,
|
||||
}
|
||||
);
|
||||
const nuevoCaso = this.casoEspecialRepository.create({
|
||||
correo: correo,
|
||||
telefono: telefono,
|
||||
institucion: institucion,
|
||||
dependencia: dependencia,
|
||||
motivo: motivo,
|
||||
direccion: direccion,
|
||||
fechaInicio: fechaInicio,
|
||||
fechaFin: fechaFin,
|
||||
fechaNacimiento: fechaNacimiento,
|
||||
carpeta: carpeta,
|
||||
archivoZip: archivoZip,
|
||||
usuario: usuario,
|
||||
carrera: carrera,
|
||||
status: status,
|
||||
creditos: creditos,
|
||||
});
|
||||
|
||||
await this.casoEspecialRepository.save(nuevoCaso);
|
||||
|
||||
@@ -102,10 +119,10 @@ export class CasoEspecialService {
|
||||
|
||||
async findAllFiltered(dto: FilterCasoEspecialDto) {
|
||||
const { pagina = 1, idStatus, nombre = '', numeroCuenta = '' } = dto;
|
||||
|
||||
|
||||
const take = 25;
|
||||
const skip = (pagina - 1) * take;
|
||||
|
||||
|
||||
const query = this.casoEspecialRepository
|
||||
.createQueryBuilder('caso')
|
||||
.leftJoinAndSelect('caso.usuario', 'usuario')
|
||||
@@ -114,32 +131,36 @@ export class CasoEspecialService {
|
||||
.take(take)
|
||||
.skip(skip)
|
||||
.orderBy('caso.updatedAt', 'DESC');
|
||||
|
||||
|
||||
if (idStatus) {
|
||||
query.andWhere('status.idStatus = :idStatus', { idStatus });
|
||||
} else {
|
||||
query.andWhere('status.idStatus > :defaultStatus', { defaultStatus: 10 });
|
||||
}
|
||||
|
||||
|
||||
if (nombre) {
|
||||
query.andWhere('usuario.nombre ILIKE :nombre', { nombre: `%${nombre}%` });
|
||||
}
|
||||
|
||||
|
||||
if (numeroCuenta) {
|
||||
query.andWhere('usuario.usuario ILIKE :numeroCuenta', { numeroCuenta: `%${numeroCuenta}%` });
|
||||
query.andWhere('usuario.usuario ILIKE :numeroCuenta', {
|
||||
numeroCuenta: `%${numeroCuenta}%`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const [result, total] = await query.getManyAndCount();
|
||||
|
||||
|
||||
return {
|
||||
count: total,
|
||||
serviciosEspeciales: result,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async liberarCasoEspecial(idCEspecial: number): Promise<{ message: string }> {
|
||||
const idCasoEspecial = this.validacion.validarNumeroEntero(idCEspecial, 'id caso especial');
|
||||
const idCasoEspecial = this.validacion.validarNumeroEntero(
|
||||
idCEspecial,
|
||||
'id caso especial',
|
||||
);
|
||||
let update = {};
|
||||
|
||||
const caso = await this.casoEspecialRepository.findOne({
|
||||
@@ -161,20 +182,17 @@ export class CasoEspecialService {
|
||||
idStatus: caso.status.idStatus === 11 ? 13 : 14,
|
||||
};
|
||||
|
||||
let sendMessage = {
|
||||
let sendMessage: SendMailDto = {
|
||||
to: caso.correo,
|
||||
|
||||
subject: correo.subject,
|
||||
|
||||
text: correo.msj,
|
||||
|
||||
html: '',
|
||||
|
||||
|
||||
}
|
||||
fecha_recibido: new Date(),
|
||||
};
|
||||
|
||||
// Envía correo
|
||||
await this.gmail.sendMail(sendMessage);
|
||||
await this.gmail.enviarCorreo(sendMessage);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
@@ -188,18 +206,21 @@ export class CasoEspecialService {
|
||||
await this.casoEspecialRepository.update({ idCasoEspecial }, update);
|
||||
|
||||
return {
|
||||
message: 'Se cambió de estatus correctamente y se envió un correo al alumno informándole de su liberación.',
|
||||
message:
|
||||
'Se cambió de estatus correctamente y se envió un correo al alumno informándole de su liberación.',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async admin(idCasoEspecial: number) {
|
||||
const id = this.validacion.validarNumeroEntero(
|
||||
idCasoEspecial,
|
||||
'id caso especial'
|
||||
'id caso especial',
|
||||
);
|
||||
|
||||
const casoEspecial = await this.casoEspecialRepository.findOne({ where: { idCasoEspecial }, relations: ['usuario', 'carrera', 'status'] });
|
||||
const casoEspecial = await this.casoEspecialRepository.findOne({
|
||||
where: { idCasoEspecial },
|
||||
relations: ['usuario', 'carrera', 'status'],
|
||||
});
|
||||
if (!casoEspecial) {
|
||||
throw new Error('No existe este Caso Especial.');
|
||||
}
|
||||
@@ -207,12 +228,14 @@ export class CasoEspecialService {
|
||||
}
|
||||
|
||||
async updateCasoEspecial(id: number, dto: UpdateCasoEspecialDto) {
|
||||
const caso = await this.casoEspecialRepository.findOne({ where: { idCasoEspecial: id } });
|
||||
|
||||
const caso = await this.casoEspecialRepository.findOne({
|
||||
where: { idCasoEspecial: id },
|
||||
});
|
||||
|
||||
if (!caso) {
|
||||
throw new NotFoundException('Este Caso Especial no existe en la db.');
|
||||
}
|
||||
|
||||
|
||||
const camposActualizables = [
|
||||
'correo',
|
||||
'fechaInicio',
|
||||
@@ -224,25 +247,26 @@ export class CasoEspecialService {
|
||||
'dependencia',
|
||||
'motivo',
|
||||
];
|
||||
|
||||
|
||||
let huboCambios = false;
|
||||
|
||||
|
||||
for (const campo of camposActualizables) {
|
||||
if (dto[campo] !== undefined) {
|
||||
(caso as any)[campo] = dto[campo];
|
||||
huboCambios = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!huboCambios) {
|
||||
throw new BadRequestException('No se envió ningún campo para actualizar este caso especial.');
|
||||
throw new BadRequestException(
|
||||
'No se envió ningún campo para actualizar este caso especial.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
await this.casoEspecialRepository.save(caso);
|
||||
|
||||
|
||||
return {
|
||||
message: 'Se guardaron correctamente los cambios de este caso especial.',
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ProgramaService } from './programa.service';
|
||||
import { ProgramaController } from './programa.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Programa } from './entities/programa.entity';
|
||||
import { Usuario } from 'src/usuario/entities/usuario.entity';
|
||||
import { UsuarioModule } from 'src/usuario/usuario.module';
|
||||
import { ValidacionService } from 'src/helpers.services/validacion.service';
|
||||
import { AuthService } from 'src/auth/auth.service';
|
||||
import { gmail } from 'src/helpers.services/gmail.service';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Programa, Servicio]), UsuarioModule],
|
||||
controllers: [ProgramaController],
|
||||
providers: [ProgramaService],
|
||||
providers: [
|
||||
ProgramaService,
|
||||
AuthService,
|
||||
ValidacionService,
|
||||
gmail,
|
||||
JwtService,
|
||||
],
|
||||
exports: [TypeOrmModule],
|
||||
})
|
||||
export class ProgramaModule {}
|
||||
|
||||
@@ -8,9 +8,19 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Servicio } from './entities/servicio.entity';
|
||||
import { Usuario } from 'src/usuario/entities/usuario.entity';
|
||||
import { ArchivoService } from 'src/helpers.services/archivo.service';
|
||||
import { UsuarioModule } from 'src/usuario/usuario.module';
|
||||
import { ProgramaModule } from 'src/programa/programa.module';
|
||||
import { Programa } from 'src/programa/entities/programa.entity';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { Auth } from 'googleapis';
|
||||
import { AuthService } from 'src/auth/auth.service';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Servicio, Usuario])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Servicio, Usuario, Programa, Carrera]),
|
||||
AuthModule,
|
||||
],
|
||||
controllers: [ServicioController],
|
||||
providers: [
|
||||
ServicioService,
|
||||
@@ -19,5 +29,6 @@ import { ArchivoService } from 'src/helpers.services/archivo.service';
|
||||
gmail,
|
||||
ArchivoService,
|
||||
],
|
||||
exports: [TypeOrmModule],
|
||||
})
|
||||
export class ServicioModule {}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { StatusService } from './status.service';
|
||||
import { StatusController } from './status.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Status } from './entities/status.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Status])],
|
||||
controllers: [StatusController],
|
||||
providers: [StatusService],
|
||||
})
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { TipoUsuarioService } from './tipo-usuario.service';
|
||||
import { CreateTipoUsuarioDto } from './dto/create-tipo-usuario.dto';
|
||||
import { UpdateTipoUsuarioDto } from './dto/update-tipo-usuario.dto';
|
||||
|
||||
@Controller('tipo-usuario')
|
||||
export class TipoUsuarioController {
|
||||
constructor(private readonly tipoUsuarioService: TipoUsuarioService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createTipoUsuarioDto: CreateTipoUsuarioDto) {
|
||||
return this.tipoUsuarioService.create(createTipoUsuarioDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.tipoUsuarioService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.tipoUsuarioService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateTipoUsuarioDto: UpdateTipoUsuarioDto) {
|
||||
return this.tipoUsuarioService.update(+id, updateTipoUsuarioDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.tipoUsuarioService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,23 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { UsuarioController } from './usuario.controller';
|
||||
import { Usuario } from './entities/usuario.entity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CarreraModule } from 'src/carrera/carrera.module';
|
||||
import { ServicioModule } from 'src/servicio/servicio.module';
|
||||
import { gmail } from 'src/helpers.services/gmail.service';
|
||||
import { Auth } from 'googleapis';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Usuario]),
|
||||
CarreraModule,
|
||||
ServicioModule,
|
||||
AuthModule,
|
||||
],
|
||||
controllers: [UsuarioController],
|
||||
providers: [UsuarioService],
|
||||
providers: [UsuarioService, gmail],
|
||||
exports: [TypeOrmModule],
|
||||
})
|
||||
export class UsuarioModule {}
|
||||
|
||||
Reference in New Issue
Block a user