Modificacines en los reportes se agregaron nuevos campos asi como la vista de consulta de informacion de los servicios
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ import { ScheduleModule } from '@nestjs/schedule';
|
||||
database: process.env.DB_DATABASE,
|
||||
password: process.env.DB_PASSWORD,
|
||||
port: Number(process.env.DB_PORT),
|
||||
synchronize: false, //Lo ponemos en false para no afectar
|
||||
synchronize: true, //Lo ponemos en false para no afectar
|
||||
dropSchema: false,
|
||||
autoLoadEntities: true,
|
||||
logger: 'advanced-console',
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { CasoEspecial } from 'src/caso-especial/entities/caso-especial.entity';
|
||||
import { CuestionarioAlumno } from 'src/cuestionario-alumno/entities/cuestionario-alumno.entity';
|
||||
import { CuestionarioAlumno2 } from 'src/cuestionario-alumno2/entities/cuestionario-alumno2.entity';
|
||||
import { CuestionarioPrograma } from 'src/cuestionario-programa/entities/cuestionario-programa.entity';
|
||||
import { CuestionarioPrograma2 } from 'src/cuestionario-programa2/entities/cuestionario-programa2.entity';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
|
||||
|
||||
@@ -15,4 +19,16 @@ export class Carrera {
|
||||
|
||||
@OneToMany(() => Servicio, (servicio) => servicio.carrera)
|
||||
servicios: Servicio[];
|
||||
|
||||
@OneToMany(() => CuestionarioAlumno2, (cuestionarioAlumno2) => cuestionarioAlumno2.carrera)
|
||||
cuestionarioAlumno2: CuestionarioAlumno2[];
|
||||
|
||||
@OneToMany(() => CuestionarioAlumno, (cuestionarioAlumno) => cuestionarioAlumno.carrera)
|
||||
cuestionarioAlumno: CuestionarioAlumno[];
|
||||
|
||||
@OneToMany(() => CuestionarioPrograma2, (cuestionarioPrograma2) => cuestionarioPrograma2.carrera)
|
||||
cuestionarioPrograma2: CuestionarioPrograma2[];
|
||||
|
||||
@OneToMany(() => CuestionarioPrograma, (CuestionarioPrograma) => CuestionarioPrograma.carrera)
|
||||
cuestionarioPrograma: CuestionarioPrograma[];
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import {
|
||||
Entity,
|
||||
@@ -5,6 +6,8 @@ import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity('cuestionario_alumno')
|
||||
@@ -121,4 +124,8 @@ export class CuestionarioAlumno {
|
||||
|
||||
@OneToMany(() => Servicio, (servicio) => servicio.cuestionarioAlumno2)
|
||||
servicio: Servicio[];
|
||||
|
||||
@ManyToOne(() => Carrera, (carrera) => carrera.cuestionarioAlumno2)
|
||||
@JoinColumn({ name: 'idCarrera' }) // nombre EXACTO de la columna en tu tabla
|
||||
carrera: Carrera;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { messageByStatus } from 'src/messageByStatus';
|
||||
import { ArchivoService } from 'src/helpers.services/archivo.service';
|
||||
import { ValidacionService } from 'src/helpers.services/validacion.service';
|
||||
import { convertArrayToCSV } from 'convert-array-to-csv';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CuestionarioAlumno2Service {
|
||||
@@ -121,6 +122,7 @@ export class CuestionarioAlumno2Service {
|
||||
where: {
|
||||
idCuestionarioAlumno: Not(IsNull()),
|
||||
},
|
||||
relations: ["carrera"] // "carrera.facultad", "servicio", "servicio.status
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,6 +131,7 @@ export class CuestionarioAlumno2Service {
|
||||
where: {
|
||||
idCuestionarioAlumno2: Not(IsNull()),
|
||||
},
|
||||
relations: ["carrera"]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,7 +139,17 @@ export class CuestionarioAlumno2Service {
|
||||
throw new BadRequestException('No hay datos para exportar');
|
||||
}
|
||||
|
||||
const data = temp.map((item) => ({ ...item }));
|
||||
console.log('Datos obtenidos para exportar:', temp[0]);
|
||||
|
||||
const data = temp.map((item => {
|
||||
const { servicio, carrera, ...rest } = item;
|
||||
return {
|
||||
...rest,
|
||||
carrera: carrera ? carrera.carrera : 'N/A',
|
||||
};
|
||||
}));
|
||||
|
||||
console.log("Datos del reporte alumnos: ", data[20])
|
||||
|
||||
await this.archivoService.eliminarArchivo(path).catch(() => null);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Carrera } from "src/carrera/entities/carrera.entity";
|
||||
import { Servicio } from "src/servicio/entities/servicio.entity";
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity('cuestionario_alumno_2')
|
||||
export class CuestionarioAlumno2 {
|
||||
@@ -140,6 +141,10 @@ export class CuestionarioAlumno2 {
|
||||
p18: string;
|
||||
|
||||
@OneToMany(()=>Servicio,(servicio)=>servicio.cuestionarioAlumno2)
|
||||
// @JoinColumn({ name: 'idServicio' })
|
||||
servicio:Servicio[];
|
||||
|
||||
@ManyToOne(()=>Carrera, (carrera)=>carrera.cuestionarioAlumno2)
|
||||
@JoinColumn({ name: 'idCarrera' }) // nombre EXACTO de la columna en tu tabla
|
||||
carrera: Carrera;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
@@ -42,5 +45,10 @@ export class CuestionarioPrograma {
|
||||
// faltaba createdAT
|
||||
|
||||
@OneToMany(() => Servicio, (servicio) => servicio.cuestionarioPrograma)
|
||||
// @JoinColumn({ name: 'idServicio' })
|
||||
servicio: Servicio[];
|
||||
|
||||
@ManyToOne(() => Carrera, (carrera) => carrera.cuestionarioPrograma)
|
||||
@JoinColumn({ name: 'idCarrera' })
|
||||
carrera: Carrera;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,15 @@ import {
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
Query,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import { CuestionarioPrograma2Service } from './cuestionario-programa2.service';
|
||||
import { CreateCuestionarioPrograma2Dto } from './dto/create-cuestionario-programa2.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { findCuestionarioProgama2Dto } from './dto/find.dto';
|
||||
import { Response } from 'express';
|
||||
|
||||
|
||||
@Controller('cuestionario-programa2')
|
||||
export class CuestionarioPrograma2Controller {
|
||||
@@ -31,8 +35,12 @@ export class CuestionarioPrograma2Controller {
|
||||
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
findAll(@Body() cuestionario: findCuestionarioProgama2Dto) {
|
||||
return this.cuestionarioPrograma2Service.getCuestionario(cuestionario);
|
||||
async findAll(@Query() cuestionario: findCuestionarioProgama2Dto, @Res() res: Response) {
|
||||
// console.log('datos para el reporte programa', cuestionario);
|
||||
// return this.cuestionarioPrograma2Service.getCuestionario(cuestionario);
|
||||
const path = await this.cuestionarioPrograma2Service.getCuestionario(cuestionario);
|
||||
|
||||
return res.download(path);
|
||||
}
|
||||
|
||||
// @Get(':id')
|
||||
|
||||
@@ -2,7 +2,7 @@ import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { CreateCuestionarioPrograma2Dto } from './dto/create-cuestionario-programa2.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { CuestionarioPrograma } from 'src/cuestionario-programa/entities/cuestionario-programa.entity';
|
||||
import { Not, Repository } from 'typeorm';
|
||||
import { IsNull, Not, Repository } from 'typeorm';
|
||||
import { CuestionarioPrograma2 } from './entities/cuestionario-programa2.entity';
|
||||
import { ArchivoService } from 'src/helpers.services/archivo.service';
|
||||
import { ValidacionService } from 'src/helpers.services/validacion.service';
|
||||
@@ -10,6 +10,7 @@ import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import { messageByStatus } from 'src/messageByStatus';
|
||||
import { convertArrayToCSV } from 'convert-array-to-csv';
|
||||
import { ServicioService } from 'src/servicio/servicio.service';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CuestionarioPrograma2Service {
|
||||
@@ -76,26 +77,52 @@ export class CuestionarioPrograma2Service {
|
||||
return respuestasRegistradas;
|
||||
}
|
||||
|
||||
async getCuestionario(dto: { version: string; year: string }) {
|
||||
const { version, year } = dto;
|
||||
const filePath = `server/uploads/${year}_cuestionario_programa.csv`;
|
||||
async getCuestionario(dto: { version: string; anio: string }) {
|
||||
const { version, anio } = dto;
|
||||
const filePath = `server/uploads/${anio}_cuestionario_programa.csv`;
|
||||
|
||||
let registros: any[];
|
||||
|
||||
if (version === 'v1') {
|
||||
registros = await this.cuestionarioRepo.find();
|
||||
registros = await this.cuestionarioRepo.find({
|
||||
where: {
|
||||
idCuestionarioPrograma: Not(IsNull()),
|
||||
},
|
||||
relations: ['carrera', 'servicio'],
|
||||
select: {
|
||||
servicio: {
|
||||
profesor: true,
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (version === 'v2') {
|
||||
registros = await this.cuestionario2Repo.find();
|
||||
registros = await this.cuestionario2Repo.find({
|
||||
where: {
|
||||
idCuestionarioPrograma2: Not(IsNull()),
|
||||
},
|
||||
relations: ['carrera', 'servicio'],
|
||||
});
|
||||
} else {
|
||||
throw new BadRequestException('Versión inválida');
|
||||
}
|
||||
|
||||
const data = registros.map((item) => ({ ...item }));
|
||||
const data = registros.map( item => {
|
||||
const { servicio, ...rest } = item;
|
||||
return {
|
||||
...rest,
|
||||
responsable: servicio?.profesor || 'N/A',
|
||||
carrera: item.carrera ? item.carrera.carrera : 'N/A',
|
||||
}
|
||||
} );
|
||||
|
||||
console.log("Informacion del reporte programa: ", data[20])
|
||||
|
||||
await this.archivoService.eliminarArchivo(filePath).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
return this.archivoService.crearArchivo(filePath, convertArrayToCSV(data));
|
||||
await this.archivoService.crearArchivo(filePath, convertArrayToCSV(data));
|
||||
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ enum Version {
|
||||
}
|
||||
|
||||
export class findCuestionarioProgama2Dto {
|
||||
@IsEnum(Version, { message: 'La version debe ser v1 o v2' })
|
||||
// @IsEnum(Version, { message: 'La version debe ser v1 o v2' })
|
||||
@IsString()
|
||||
@Length(2, 2, { message: 'La version debe ser v1 o v2' })
|
||||
version: Version;
|
||||
|
||||
@IsString()
|
||||
@Length(4, 4, { message: 'El número debe tener exactamente 4 dígitos' })
|
||||
year: string;
|
||||
anio: string;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
@@ -90,6 +93,11 @@ export class CuestionarioPrograma2 {
|
||||
@Column({ name: 'p7', type: 'varchar', length: 200, nullable: true })
|
||||
p7?: string;
|
||||
|
||||
@OneToMany(() => Servicio, (servicio) => servicio.cuestionarioAlumno2)
|
||||
@OneToMany(() => Servicio, (servicio) => servicio.cuestionarioPrograma2)
|
||||
// @JoinColumn({ name: 'idServicio' })
|
||||
servicio: Servicio[];
|
||||
|
||||
@ManyToOne(() => Carrera, (carrera) => carrera.cuestionarioPrograma2)
|
||||
@JoinColumn({ name: 'idCarrera' })
|
||||
carrera: Carrera;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,8 @@ export class ServicioService {
|
||||
'servicio.idCuestionarioAlumno2',
|
||||
'servicio.idCuestionarioPrograma',
|
||||
'servicio.idCuestionarioPrograma2',
|
||||
'servicio.programaInterno',
|
||||
'servicio.profesor',
|
||||
|
||||
'usuario.idUsuario',
|
||||
'usuario.usuario',
|
||||
@@ -1295,6 +1297,9 @@ export class ServicioService {
|
||||
fechaLiberacion: s.fechaLiberacion
|
||||
? this.archivoService.crearDDMMAAAA(s.fechaLiberacion)
|
||||
: '',
|
||||
AcatlanContigo: s.programa.acatlan ? 'Sí' : 'No',
|
||||
programaInterno: s.programaInterno,
|
||||
responsable: s.usuario.nombre,
|
||||
institucion: s.programa.institucion,
|
||||
dependencia: s.programa.dependencia,
|
||||
programa: s.programa.programa,
|
||||
|
||||
Reference in New Issue
Block a user