add data to reports
This commit is contained in:
@@ -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],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface ParticipacionAlumno {
|
||||
carrera: string;
|
||||
participacion: number;
|
||||
porcentajeParticipacion: number;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ParticipacionAlumno } from './ParticipacionAlumno.interface';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { UsuarioEntity } from '../entities/usuario.entity';
|
||||
import { TipoUsuarioEntity } from '../entities/tipoUsuario.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ParticipacionService {
|
||||
constructor(
|
||||
@InjectRepository(UsuarioEntity)
|
||||
private readonly reportesRepository: Repository<any>,
|
||||
@InjectRepository(TipoUsuarioEntity)
|
||||
private readonly tUReportesRepository: 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 getTotalUsuarios(): Promise<ParticipacionAlumno[]> {
|
||||
const queryBuilder =
|
||||
await this.tUReportesRepository.createQueryBuilder('tu'); // Alias for 'tipos_usuarios'
|
||||
|
||||
return (await queryBuilder
|
||||
.select('tu.tipo AS tipo_usuario')
|
||||
.addSelect('COUNT(u.id) AS total_usuarios')
|
||||
.innerJoin('tu.usuarios', 'u') // Assuming 'usuarios' is the relationship property
|
||||
.groupBy('tu.id, tu.tipo')
|
||||
.getRawMany()) as any[]; // Cast to the interface
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { ParticipacionAlumno } from './ParticipacionAlumno.interface';
|
||||
import { ParticipacionService } from './participacionAlumno.service';
|
||||
|
||||
@Controller('reportes')
|
||||
export class ReportesController {
|
||||
constructor(private readonly participacionService: ParticipacionService) {}
|
||||
|
||||
@Get('participacionAlumnos')
|
||||
async geParticipacionAlumno(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getParticipacionAlumno();
|
||||
}
|
||||
|
||||
@Get('totalParticipantes')
|
||||
async getTotalParticipantes(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getTotalUsuarios();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([UsuarioEntity, TipoUsuarioEntity])],
|
||||
providers: [ParticipacionService],
|
||||
controllers: [ReportesController],
|
||||
exports: [ParticipacionService],
|
||||
})
|
||||
export class ReportesModule {}
|
||||
Reference in New Issue
Block a user