total por carrera
This commit is contained in:
@@ -4,6 +4,7 @@ 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';
|
||||
|
||||
@Injectable()
|
||||
export class ParticipacionService {
|
||||
@@ -12,6 +13,8 @@ export class ParticipacionService {
|
||||
private readonly reportesRepository: Repository<any>,
|
||||
@InjectRepository(TipoUsuarioEntity)
|
||||
private readonly tUReportesRepository: Repository<any>,
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carrearasReportesRepository: Repository<any>,
|
||||
) {}
|
||||
|
||||
async getParticipacionAlumno(): Promise<ParticipacionAlumno[]> {
|
||||
@@ -32,13 +35,25 @@ export class ParticipacionService {
|
||||
|
||||
async getTotalUsuarios(): Promise<ParticipacionAlumno[]> {
|
||||
const queryBuilder =
|
||||
await this.tUReportesRepository.createQueryBuilder('tu'); // Alias for 'tipos_usuarios'
|
||||
|
||||
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') // Assuming 'usuarios' is the relationship property
|
||||
.innerJoin('tu.usuarios', 'u')
|
||||
.groupBy('tu.id, tu.tipo')
|
||||
.getRawMany()) as any[]; // Cast to the interface
|
||||
.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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,9 @@ export class ReportesController {
|
||||
async getTotalParticipantes(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getTotalUsuarios();
|
||||
}
|
||||
|
||||
@Get('totalAlumnosPorCarrera')
|
||||
async getTotalAlumnosPorCarrera(): Promise<ParticipacionAlumno[]> {
|
||||
return this.participacionService.getTotalAlumnos();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ 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';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([UsuarioEntity, TipoUsuarioEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([UsuarioEntity, TipoUsuarioEntity, Carrera]),
|
||||
],
|
||||
providers: [ParticipacionService],
|
||||
controllers: [ReportesController],
|
||||
exports: [ParticipacionService],
|
||||
|
||||
Reference in New Issue
Block a user