Compare commits
9 Commits
V1.0
...
development
| Author | SHA1 | Date | |
|---|---|---|---|
| 25e86d2eb2 | |||
| f77bb4b5ce | |||
| e10a06e1ff | |||
| c276116295 | |||
| 35926405cc | |||
| 93b2642860 | |||
| 2b2834e121 | |||
| b4ee82e6ae | |||
| b130428835 |
@@ -23,6 +23,8 @@ import { LineasProgramaticasModule } from './lineasProgramaticas/lineasProgramat
|
||||
import { CarreraModule } from './carrera/carreras.module';
|
||||
import { ComentariosModule } from './comentarios/comentarios.module';
|
||||
import { ComentarioLineasProgramaticas } from './entities/comentarioLineasProgramaticas.entity';
|
||||
import { ReportesController } from './reportes/reportes.controller';
|
||||
import { ReportesModule } from './reportes/reportes.module';
|
||||
config({ path: '.env' });
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -32,6 +34,7 @@ config({ path: '.env' });
|
||||
ComentariosModule,
|
||||
LineasProgramaticasModule,
|
||||
CarreraModule,
|
||||
ReportesModule,
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
@@ -64,6 +67,7 @@ config({ path: '.env' });
|
||||
UsuarioController,
|
||||
EjesEstrategicosController,
|
||||
LineasProgramaticasController,
|
||||
ReportesController,
|
||||
],
|
||||
providers: [AppService, EjesEstrategicosService, LineasProgramaticasService],
|
||||
})
|
||||
|
||||
@@ -20,6 +20,7 @@ export class AuthService {
|
||||
switch (loginDto.tipo_usuario) {
|
||||
case 1:
|
||||
// Administrador
|
||||
user = await this.usersService.findAdmin(loginDto);
|
||||
break;
|
||||
case 2:
|
||||
// Alumno
|
||||
@@ -27,9 +28,15 @@ export class AuthService {
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Trabajadores académicos o base
|
||||
// Trabajadores
|
||||
user = await this.usersService.findWorker(loginDto);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// Académicos
|
||||
user = await this.usersService.findWorker(loginDto);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BadRequestException();
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface ParticipacionAlumno {
|
||||
carrera: string;
|
||||
participacion: number;
|
||||
porcentajeParticipacion: number;
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Repository, SelectQueryBuilder } from 'typeorm';
|
||||
import { ParticipacionAlumno } from './ParticipacionAlumno.interface';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { UsuarioEntity } from '../entities/usuario.entity';
|
||||
import { TipoUsuarioEntity } from '../entities/tipoUsuario.entity';
|
||||
import { Carrera } from '../entities/carreras.entity';
|
||||
import { ComentarioLineasProgramaticas } from '../entities/comentarioLineasProgramaticas.entity';
|
||||
import { LineaProgramatica } from '../entities/LineaProgramatica.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ParticipacionService {
|
||||
constructor(
|
||||
@InjectRepository(UsuarioEntity)
|
||||
private readonly reportesRepository: Repository<any>,
|
||||
@InjectRepository(TipoUsuarioEntity)
|
||||
private readonly tUReportesRepository: Repository<any>,
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carrearasReportesRepository: Repository<any>,
|
||||
@InjectRepository(ComentarioLineasProgramaticas)
|
||||
private readonly comentarioLineaProgramaticaReportesRepository: Repository<any>,
|
||||
) {}
|
||||
|
||||
async getParticipacionAlumno(): Promise<ParticipacionAlumno[]> {
|
||||
const queryBuilder = await this.reportesRepository.createQueryBuilder('u'); // Inject 'userRepository' instead
|
||||
|
||||
return (await queryBuilder
|
||||
.select('c.nombre AS carrera')
|
||||
.addSelect('COUNT(DISTINCT u.id) AS participacion')
|
||||
.addSelect(
|
||||
'(COUNT(DISTINCT u.id) / (SELECT COUNT(*) FROM usuarios WHERE carrera_id = u.carrera_id AND tipo_usuario_id = 2)) * 100 AS porcentajeParticipacion',
|
||||
)
|
||||
.innerJoin('u.comentarios', 'clp')
|
||||
.innerJoin('u.carrera', 'c')
|
||||
.where('u.tipo_usuario_id = 2')
|
||||
.groupBy('c.nombre')
|
||||
.getRawMany()) as ParticipacionAlumno[];
|
||||
}
|
||||
|
||||
async getParticipacionTrabajador(): Promise<SelectQueryBuilder<any>> {
|
||||
const result = await this.reportesRepository
|
||||
.createQueryBuilder('usuarios')
|
||||
.select('COUNT(DISTINCT usuarios.id)', 'Participacion Trabajadores')
|
||||
.addSelect(
|
||||
`
|
||||
(COUNT(DISTINCT usuarios.id) * 100.0 / (SELECT COUNT(*) FROM usuarios WHERE usuarios.tipo_usuario_id = 3)) AS PorcentajeParticipacion
|
||||
`,
|
||||
)
|
||||
.innerJoin('usuarios.comentarios', 'clp')
|
||||
.where('usuarios.tipo_usuario_id = 3')
|
||||
.getRawOne();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getParticipacionAcademico(): Promise<SelectQueryBuilder<any>> {
|
||||
const result = await this.reportesRepository
|
||||
.createQueryBuilder('usuarios')
|
||||
.select('COUNT(DISTINCT usuarios.id)', 'Participacion Trabajadores')
|
||||
.addSelect(
|
||||
`
|
||||
(COUNT(DISTINCT usuarios.id) * 100.0 / (SELECT COUNT(*) FROM usuarios WHERE usuarios.tipo_usuario_id = 4)) AS PorcentajeParticipacion
|
||||
`,
|
||||
)
|
||||
.innerJoin('usuarios.comentarios', 'clp')
|
||||
.where('usuarios.tipo_usuario_id = 4')
|
||||
.getRawOne();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getTotalUsuarios(): Promise<ParticipacionAlumno[]> {
|
||||
const queryBuilder =
|
||||
await this.tUReportesRepository.createQueryBuilder('tu');
|
||||
return (await queryBuilder
|
||||
.select('tu.tipo AS tipo_usuario')
|
||||
.addSelect('COUNT(u.id) AS total_usuarios')
|
||||
.innerJoin('tu.usuarios', 'u')
|
||||
.groupBy('tu.id, tu.tipo')
|
||||
.getRawMany()) as any[];
|
||||
}
|
||||
|
||||
async getTotalAlumnos(): Promise<ParticipacionAlumno[]> {
|
||||
const queryBuilder =
|
||||
await this.carrearasReportesRepository.createQueryBuilder('c');
|
||||
|
||||
return (await queryBuilder
|
||||
.select('c.nombre AS carrera')
|
||||
.addSelect('COUNT(u.id) AS total_alumnos')
|
||||
.innerJoin('c.usuarios', 'u')
|
||||
.where('u.tipo_usuario_id = 2')
|
||||
.groupBy('c.id, c.nombre')
|
||||
.getRawMany()) as any[]; // Cast to
|
||||
}
|
||||
|
||||
async getReporteGeneral(): Promise<any> {
|
||||
const result = await this.comentarioLineaProgramaticaReportesRepository
|
||||
.createQueryBuilder('clp')
|
||||
.innerJoin('clp.lineaProgramatica', 'lp')
|
||||
.innerJoin('lp.ejeEstrategico', 'ee')
|
||||
.innerJoin('clp.usuario', 'u')
|
||||
.innerJoin('u.tipoUsuario', 'tu')
|
||||
.leftJoin('u.carrera', 'c')
|
||||
.select([
|
||||
'clp.id as Id_Comentario',
|
||||
'clp.comentario as Comentario',
|
||||
'lp.descripcion AS Linea_Programatica',
|
||||
'ee.nombre AS Eje_Estrategico',
|
||||
'ee.objetivo as Objetivo',
|
||||
'u.numero_identificacion AS numero_Cuenta_O_Trabajador',
|
||||
'tu.tipo as Tipo',
|
||||
"CASE WHEN tu.id = 2 THEN c.nombre ELSE 'No aplica' END AS carrera",
|
||||
])
|
||||
.getRawMany();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Controller, Get, UseGuards } from "@nestjs/common";
|
||||
import { ParticipacionAlumno } from './ParticipacionAlumno.interface';
|
||||
import { ParticipacionService } from './participacionAlumno.service';
|
||||
import { AuthGuard } from "../auth/auth.guard";
|
||||
|
||||
@Controller('reportes')
|
||||
export class ReportesController {
|
||||
constructor(private readonly participacionService: ParticipacionService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('participacionAlumnos')
|
||||
async geParticipacionAlumno(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getParticipacionAlumno();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('participacionTrabajador')
|
||||
async geParticipacionTrabajador(): Promise<any> {
|
||||
return this.participacionService.getParticipacionTrabajador();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('participacionAcademico')
|
||||
async geParticipacionAcademico(): Promise<any> {
|
||||
return this.participacionService.getParticipacionAcademico();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('totalParticipantes')
|
||||
async getTotalParticipantes(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getTotalUsuarios();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('totalAlumnosPorCarrera')
|
||||
async getTotalAlumnosPorCarrera(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getTotalAlumnos();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('reporteGeneral')
|
||||
async getReporteGeneral(): Promise<any> {
|
||||
return this.participacionService.getReporteGeneral();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ParticipacionService } from './participacionAlumno.service';
|
||||
import { ReportesController } from './reportes.controller';
|
||||
import { UsuarioEntity } from '../entities/usuario.entity';
|
||||
import { TipoUsuarioEntity } from '../entities/tipoUsuario.entity';
|
||||
import { Carrera } from '../entities/carreras.entity';
|
||||
import { LineaProgramatica } from "../entities/LineaProgramatica.entity";
|
||||
import { ComentarioLineasProgramaticas } from "../entities/comentarioLineasProgramaticas.entity";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([UsuarioEntity, TipoUsuarioEntity, Carrera, ComentarioLineasProgramaticas]),
|
||||
],
|
||||
providers: [ParticipacionService],
|
||||
controllers: [ReportesController],
|
||||
exports: [ParticipacionService],
|
||||
})
|
||||
export class ReportesModule {}
|
||||
@@ -40,4 +40,14 @@ export class UsersService {
|
||||
rfc,
|
||||
});
|
||||
}
|
||||
|
||||
findAdmin(loginDto: LoginDTO): Promise<UsuarioEntity | null> {
|
||||
const numero_identificacion = loginDto.numero_identificacion;
|
||||
const rfc = loginDto.rfc;
|
||||
return this.usersRepository.findOneBy({
|
||||
numero_identificacion,
|
||||
rfc,
|
||||
tipo_usuario_id:1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user