|
|
|
@@ -4,14 +4,12 @@ import {
|
|
|
|
|
NotFoundException,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
import { Carrera } from '../carrera/entity/carrera.entity';
|
|
|
|
|
import { FindOperator, Like, Repository } from 'typeorm';
|
|
|
|
|
import { InstitucionCarrera } from '../institucion-carrera/entity/institucion-carrera.entity';
|
|
|
|
|
import { Institucion } from '../institucion/entity/institucion.entity';
|
|
|
|
|
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
|
|
|
|
import { Usuario } from './entity/usuario.entity';
|
|
|
|
|
import { BcryptService } from '../bcrypt/bcrypt.service';
|
|
|
|
|
import { CarreraService } from '../carrera/carrera.service';
|
|
|
|
|
import { InstitucionCarreraService } from '../institucion-carrera/institucion-carrera.service';
|
|
|
|
|
import { InstitucionService } from '../institucion/institucion.service';
|
|
|
|
|
import { NodemailerService } from '../nodemailer/nodemailer.service';
|
|
|
|
@@ -22,9 +20,8 @@ export class UsuarioService {
|
|
|
|
|
constructor(
|
|
|
|
|
@InjectRepository(Usuario) private repository: Repository<Usuario>,
|
|
|
|
|
private bcryptService: BcryptService,
|
|
|
|
|
private carreraService: CarreraService,
|
|
|
|
|
private institucionService: InstitucionService,
|
|
|
|
|
private InstitucionCarreraService: InstitucionCarreraService,
|
|
|
|
|
private institucionCarreraService: InstitucionCarreraService,
|
|
|
|
|
private nodemailerService: NodemailerService,
|
|
|
|
|
private tipoUsuarioService: TipoUsuarioService,
|
|
|
|
|
) {}
|
|
|
|
@@ -36,7 +33,7 @@ export class UsuarioService {
|
|
|
|
|
id_institucion_carrera?: number,
|
|
|
|
|
) {
|
|
|
|
|
const carrera = id_institucion_carrera
|
|
|
|
|
? await this.InstitucionCarreraService.findById(id_institucion_carrera)
|
|
|
|
|
? await this.institucionCarreraService.findById(id_institucion_carrera)
|
|
|
|
|
: null;
|
|
|
|
|
const institucion = await this.institucionService.findById(id_institucion);
|
|
|
|
|
const tipoUsuario = await this.tipoUsuarioService.findById(id_tipo_usuario);
|
|
|
|
@@ -80,35 +77,43 @@ export class UsuarioService {
|
|
|
|
|
<p>Pc Puma Solicita</p>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
escolares() {}
|
|
|
|
|
|
|
|
|
|
async findAll(filtros: {
|
|
|
|
|
pagina: string;
|
|
|
|
|
id_carrera?: string;
|
|
|
|
|
id_institucion_carrera?: string;
|
|
|
|
|
id_institucion?: string;
|
|
|
|
|
id_tipo_usuario?: string;
|
|
|
|
|
usuario?: string;
|
|
|
|
|
}) {
|
|
|
|
|
const busqueda: {
|
|
|
|
|
// carrera?: Carrera;
|
|
|
|
|
institucion?: Institucion;
|
|
|
|
|
tipoUsuario?: TipoUsuario;
|
|
|
|
|
usuario?: string;
|
|
|
|
|
} = {};
|
|
|
|
|
where: {
|
|
|
|
|
carrera?: InstitucionCarrera;
|
|
|
|
|
institucion?: Institucion;
|
|
|
|
|
tipoUsuario?: TipoUsuario;
|
|
|
|
|
usuario?: FindOperator<string>;
|
|
|
|
|
};
|
|
|
|
|
skip;
|
|
|
|
|
take;
|
|
|
|
|
} = { where: {}, skip: (parseInt(filtros.pagina) - 1) * 25, take: 25 };
|
|
|
|
|
const carrera = filtros.id_institucion_carrera
|
|
|
|
|
? await this.institucionCarreraService.findById(
|
|
|
|
|
parseInt(filtros.id_institucion_carrera),
|
|
|
|
|
)
|
|
|
|
|
: null;
|
|
|
|
|
const institucion = filtros.id_institucion
|
|
|
|
|
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
|
|
|
|
: null;
|
|
|
|
|
const tipoUsuario = filtros.id_tipo_usuario
|
|
|
|
|
? await this.tipoUsuarioService.findById(parseInt(filtros.id_tipo_usuario))
|
|
|
|
|
: null;
|
|
|
|
|
const carrera = filtros.id_carrera
|
|
|
|
|
? await this.carreraService.findById(parseInt(filtros.id_carrera))
|
|
|
|
|
? await this.tipoUsuarioService.findById(
|
|
|
|
|
parseInt(filtros.id_tipo_usuario),
|
|
|
|
|
)
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
/* buscar usnado like */
|
|
|
|
|
if (filtros.usuario) busqueda.usuario = filtros.usuario;
|
|
|
|
|
if (institucion) busqueda.institucion = institucion;
|
|
|
|
|
if (tipoUsuario) busqueda.tipoUsuario = tipoUsuario;
|
|
|
|
|
// if (carrera) busqueda.carrera = carrera;
|
|
|
|
|
/* falta página, paginado */
|
|
|
|
|
if (filtros.usuario) busqueda.where.usuario = Like(`${filtros.usuario}%`);
|
|
|
|
|
if (carrera) busqueda.where.carrera = carrera;
|
|
|
|
|
if (institucion) busqueda.where.institucion = institucion;
|
|
|
|
|
if (tipoUsuario) busqueda.where.tipoUsuario = tipoUsuario;
|
|
|
|
|
return this.repository.find(busqueda);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -180,7 +185,7 @@ export class UsuarioService {
|
|
|
|
|
html: this.correoPassword(password),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.then((_) => ({ message: 'Se creo correctamente un usuario.' }));
|
|
|
|
|
.then((_) => ({ message: 'Se registro correctamente un usuario.' }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(attrs: Partial<Usuario>) {
|
|
|
|
|