Compare commits
6 Commits
V1.0
...
admin_side
| Author | SHA1 | Date | |
|---|---|---|---|
| e9184963f5 | |||
| 2b2834e121 | |||
| b4ee82e6ae | |||
| b130428835 | |||
| 3a356887f7 | |||
| afafad2d4e |
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "source ~/.nvm/nvm.sh && nvm use 20.17.0 && nest start",
|
"start": "nest start",
|
||||||
"start:dev": "nest start --watch",
|
"start:dev": "nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "node dist/main",
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import { LineasProgramaticasModule } from './lineasProgramaticas/lineasProgramat
|
|||||||
import { CarreraModule } from './carrera/carreras.module';
|
import { CarreraModule } from './carrera/carreras.module';
|
||||||
import { ComentariosModule } from './comentarios/comentarios.module';
|
import { ComentariosModule } from './comentarios/comentarios.module';
|
||||||
import { ComentarioLineasProgramaticas } from './entities/comentarioLineasProgramaticas.entity';
|
import { ComentarioLineasProgramaticas } from './entities/comentarioLineasProgramaticas.entity';
|
||||||
|
import { ReportesController } from './reportes/reportes.controller';
|
||||||
|
import { ReportesModule } from './reportes/reportes.module';
|
||||||
|
import { Direccion } from './entities/direccion.entity';
|
||||||
|
import { DireccionModule } from './direccion/direccion.module';
|
||||||
config({ path: '.env' });
|
config({ path: '.env' });
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -32,6 +36,8 @@ config({ path: '.env' });
|
|||||||
ComentariosModule,
|
ComentariosModule,
|
||||||
LineasProgramaticasModule,
|
LineasProgramaticasModule,
|
||||||
CarreraModule,
|
CarreraModule,
|
||||||
|
ReportesModule,
|
||||||
|
DireccionModule,
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
}),
|
}),
|
||||||
@@ -51,6 +57,7 @@ config({ path: '.env' });
|
|||||||
LineaProgramatica,
|
LineaProgramatica,
|
||||||
TipoUsuarioEntity,
|
TipoUsuarioEntity,
|
||||||
UsuarioEntity,
|
UsuarioEntity,
|
||||||
|
Direccion,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
JwtModule.register({
|
JwtModule.register({
|
||||||
@@ -64,6 +71,7 @@ config({ path: '.env' });
|
|||||||
UsuarioController,
|
UsuarioController,
|
||||||
EjesEstrategicosController,
|
EjesEstrategicosController,
|
||||||
LineasProgramaticasController,
|
LineasProgramaticasController,
|
||||||
|
ReportesController,
|
||||||
],
|
],
|
||||||
providers: [AppService, EjesEstrategicosService, LineasProgramaticasService],
|
providers: [AppService, EjesEstrategicosService, LineasProgramaticasService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Header,
|
||||||
|
HttpCode,
|
||||||
|
Logger,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Query,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { AuthGuard } from '../auth/auth.guard';
|
||||||
|
import { DireccionService } from './direccion.service';
|
||||||
|
import { isUndefined } from '@nestjs/common/utils/shared.utils';
|
||||||
|
import { DireccionDTO } from '../dtos/direccionDTO';
|
||||||
|
import { Delete } from '@nestjs/common/decorators/http/request-mapping.decorator';
|
||||||
|
|
||||||
|
@Controller('direccion')
|
||||||
|
export class DireccionController {
|
||||||
|
constructor(private readonly direccionService: DireccionService) {}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@Get('direccion')
|
||||||
|
@HttpCode(200)
|
||||||
|
getDireccion() {
|
||||||
|
Logger.log('Direccion', 'getDireccion');
|
||||||
|
return this.direccionService.findDirecciones();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@Get('direccionById')
|
||||||
|
@HttpCode(200)
|
||||||
|
getDireccionById(@Query('direccionId') direccionId: number) {
|
||||||
|
Logger.log('Direccion', 'getDireccionById');
|
||||||
|
if (!isUndefined(direccionId)) {
|
||||||
|
return this.direccionService.findDireccionById(direccionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@Post('addDireccion')
|
||||||
|
@HttpCode(200)
|
||||||
|
setDireccion(@Body() direccion: DireccionDTO) {
|
||||||
|
Logger.log('Direccion', 'setDireccion');
|
||||||
|
return this.direccionService.addDireccion(direccion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@Put('updateDireccion')
|
||||||
|
@HttpCode(200)
|
||||||
|
updateDireccion(@Body() direccion: DireccionDTO) {
|
||||||
|
Logger.log('Direccion', 'updateDireccion');
|
||||||
|
return this.direccionService.updateDireccion(direccion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@Delete('deleteDireccion')
|
||||||
|
@HttpCode(200)
|
||||||
|
deleteDireccion(@Body() direccion: DireccionDTO) {
|
||||||
|
Logger.log('Direccion', 'deleteDireccion');
|
||||||
|
return this.direccionService.deleteDireccion(direccion);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Direccion } from '../entities/direccion.entity';
|
||||||
|
import { DireccionService } from './direccion.service';
|
||||||
|
import { DireccionController } from './direccion.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([Direccion])],
|
||||||
|
providers: [DireccionService],
|
||||||
|
controllers: [DireccionController],
|
||||||
|
exports: [TypeOrmModule.forFeature([DireccionService])],
|
||||||
|
})
|
||||||
|
export class DireccionModule {}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { DeleteResult, Repository, UpdateResult } from 'typeorm';
|
||||||
|
import { Direccion } from '../entities/direccion.entity';
|
||||||
|
import { DireccionDTO } from '../dtos/direccionDTO';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DireccionService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Direccion)
|
||||||
|
private direccionRepository: Repository<Direccion>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
findDirecciones(): Promise<Direccion[]> {
|
||||||
|
return this.direccionRepository.find({});
|
||||||
|
}
|
||||||
|
|
||||||
|
findDireccionById(direccionId: number): Promise<Direccion[]> {
|
||||||
|
return this.direccionRepository.findBy({ id: direccionId });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
addDireccion(direccion: DireccionDTO): Promise<Direccion> {
|
||||||
|
return this.direccionRepository.save(direccion);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDireccion(direccion: DireccionDTO): Promise<UpdateResult> {
|
||||||
|
return this.direccionRepository.update({ direccion });
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteDireccion(direccion: Direccion): Promise<DeleteResult> {
|
||||||
|
return this.direccionRepository.delete({
|
||||||
|
id: direccion.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { IsDefined, IsInt, IsNotEmpty, IsString } from "@nestjs/class-validator";
|
||||||
|
|
||||||
|
export class DireccionDTO {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly primer_nombre: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
readonly segundo_nombre: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly apellido_paterno: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly apellido_materno: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly inicio_periodo: Date;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly fin_periodo: Date;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly inicio_periodo_encuesta: Date;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDefined()
|
||||||
|
readonly fin_periodo_encuesta: Date;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
readonly id: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('direccion')
|
||||||
|
export class Direccion {
|
||||||
|
|
||||||
|
@PrimaryGeneratedColumn('increment', { type: 'int' })
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column('varchar', { length: 100 })
|
||||||
|
primer_nombre: string;
|
||||||
|
|
||||||
|
@Column('varchar', { length: 100 })
|
||||||
|
segundo_nombre: string;
|
||||||
|
|
||||||
|
@Column('varchar', { length: 100 })
|
||||||
|
apellido_paterno: string;
|
||||||
|
|
||||||
|
@Column('varchar', { length: 100 })
|
||||||
|
apellido_materno: string;
|
||||||
|
|
||||||
|
@Column('date')
|
||||||
|
inicio_periodo: Date;
|
||||||
|
|
||||||
|
@Column('date')
|
||||||
|
fin_periodo: Date;
|
||||||
|
|
||||||
|
@Column('date')
|
||||||
|
inicio_periodo_encuesta: Date;
|
||||||
|
|
||||||
|
@Column('date')
|
||||||
|
fin_periodo_encuesta: Date;
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
OneToMany,
|
||||||
|
ManyToOne,
|
||||||
|
} from 'typeorm';
|
||||||
import { LineaProgramatica } from './LineaProgramatica.entity';
|
import { LineaProgramatica } from './LineaProgramatica.entity';
|
||||||
|
import { Direccion } from './direccion.entity';
|
||||||
|
|
||||||
@Entity('ejes_estrategicos')
|
@Entity('ejes_estrategicos')
|
||||||
export class EjeEstrategico {
|
export class EjeEstrategico {
|
||||||
@@ -17,4 +24,7 @@ export class EjeEstrategico {
|
|||||||
(lineaProgramatica) => lineaProgramatica.ejeEstrategico,
|
(lineaProgramatica) => lineaProgramatica.ejeEstrategico,
|
||||||
)
|
)
|
||||||
lineasProgramaticas: LineaProgramatica[];
|
lineasProgramaticas: LineaProgramatica[];
|
||||||
|
|
||||||
|
@ManyToOne(() => Direccion, (direccion) => direccion.id)
|
||||||
|
direccion: Direccion;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export interface ParticipacionAlumno {
|
||||||
|
carrera: string;
|
||||||
|
participacion: number;
|
||||||
|
porcentajeParticipacion: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
@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>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
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 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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('participacionTrabajador')
|
||||||
|
async geParticipacionTrabajador(): Promise<any> {
|
||||||
|
return this.participacionService.getParticipacionTrabajador();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('totalParticipantes')
|
||||||
|
async getTotalParticipantes(): Promise<ParticipacionAlumno[]> {
|
||||||
|
return this.participacionService.getTotalUsuarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('totalAlumnosPorCarrera')
|
||||||
|
async getTotalAlumnosPorCarrera(): Promise<ParticipacionAlumno[]> {
|
||||||
|
return this.participacionService.getTotalAlumnos();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([UsuarioEntity, TipoUsuarioEntity, Carrera]),
|
||||||
|
],
|
||||||
|
providers: [ParticipacionService],
|
||||||
|
controllers: [ReportesController],
|
||||||
|
exports: [ParticipacionService],
|
||||||
|
})
|
||||||
|
export class ReportesModule {}
|
||||||
Reference in New Issue
Block a user