se agregaron caso-esp, cust-alum, helpers
This commit is contained in:
@@ -7,28 +7,28 @@ import { UpdateCuestionarioPrograma2Dto } from './dto/update-cuestionario-progra
|
||||
export class CuestionarioPrograma2Controller {
|
||||
constructor(private readonly cuestionarioPrograma2Service: CuestionarioPrograma2Service) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createCuestionarioPrograma2Dto: CreateCuestionarioPrograma2Dto) {
|
||||
return this.cuestionarioPrograma2Service.create(createCuestionarioPrograma2Dto);
|
||||
}
|
||||
// @Post()
|
||||
// create(@Body() createCuestionarioPrograma2Dto: CreateCuestionarioPrograma2Dto) {
|
||||
// return this.cuestionarioPrograma2Service.create(createCuestionarioPrograma2Dto);
|
||||
// }
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.cuestionarioPrograma2Service.findAll();
|
||||
}
|
||||
// @Get()
|
||||
// findAll() {
|
||||
// return this.cuestionarioPrograma2Service.findAll();
|
||||
// }
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.cuestionarioPrograma2Service.findOne(+id);
|
||||
}
|
||||
// @Get(':id')
|
||||
// findOne(@Param('id') id: string) {
|
||||
// return this.cuestionarioPrograma2Service.findOne(+id);
|
||||
// }
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateCuestionarioPrograma2Dto: UpdateCuestionarioPrograma2Dto) {
|
||||
return this.cuestionarioPrograma2Service.update(+id, updateCuestionarioPrograma2Dto);
|
||||
}
|
||||
// @Patch(':id')
|
||||
// update(@Param('id') id: string, @Body() updateCuestionarioPrograma2Dto: UpdateCuestionarioPrograma2Dto) {
|
||||
// return this.cuestionarioPrograma2Service.update(+id, updateCuestionarioPrograma2Dto);
|
||||
// }
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.cuestionarioPrograma2Service.remove(+id);
|
||||
}
|
||||
// @Delete(':id')
|
||||
// remove(@Param('id') id: string) {
|
||||
// return this.cuestionarioPrograma2Service.remove(+id);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,15 +1,101 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { CreateCuestionarioPrograma2Dto } from './dto/create-cuestionario-programa2.dto';
|
||||
import { UpdateCuestionarioPrograma2Dto } from './dto/update-cuestionario-programa2.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { CuestionarioPrograma } from 'src/cuestionario-programa/entities/cuestionario-programa.entity';
|
||||
import { 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';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import { messageByStatus } from 'src/messageByStatus';
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
|
||||
@Injectable()
|
||||
export class CuestionarioPrograma2Service {
|
||||
create(createCuestionarioPrograma2Dto: CreateCuestionarioPrograma2Dto) {
|
||||
return 'This action adds a new cuestionarioPrograma2';
|
||||
constructor(
|
||||
@InjectRepository(CuestionarioPrograma)
|
||||
private cuestionarioRepo: Repository<CuestionarioPrograma>,
|
||||
@InjectRepository(CuestionarioPrograma2)
|
||||
private cuestionario2Repo: Repository<CuestionarioPrograma2>,
|
||||
@InjectRepository(Servicio)
|
||||
private servicioRepository:Repository<Servicio>,
|
||||
private archivoService:ArchivoService,
|
||||
private validacionService:ValidacionService,
|
||||
) {}
|
||||
|
||||
async create(cuestionarioPrograma2: CreateCuestionarioPrograma2Dto) {
|
||||
let idServicio = cuestionarioPrograma2.idServicio;
|
||||
let cuestionario = this.validacionService.validarCuestionarioPrograma2(cuestionarioPrograma2);
|
||||
|
||||
let servicio = await this.servicioRepository.findOne({where:{idServicio}});
|
||||
if(!servicio){
|
||||
throw new Error('No existe este Servicio Social.');
|
||||
}
|
||||
if(servicio.cuestionarioPrograma2.idCuestionarioPrograma2){
|
||||
throw new Error('Este Servicio Social ya cuenta con cuestionario de alumno');
|
||||
}
|
||||
|
||||
console.log('el servicio social si existe', servicio);
|
||||
|
||||
console.log('antes de create ques2');
|
||||
if (messageByStatus.hasOwnProperty(servicio.status.idStatus))
|
||||
throw new Error(messageByStatus[servicio.status.idStatus]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
console.log('despues de registrar cuestionario', cuestionario);
|
||||
|
||||
let respuestasRegistradas = await this.cuestionario2Repo.save(cuestionario);
|
||||
|
||||
// si el cuestionario ya existe solo hay que actualizar el id de cuestionarioprograma o alumno
|
||||
|
||||
|
||||
console.log("registrar id en servicio en cuestionario 2");
|
||||
|
||||
let x = await this.servicioRepository.update(
|
||||
|
||||
{ idServicio },
|
||||
{ cuestionarioPrograma2: respuestasRegistradas }
|
||||
)
|
||||
|
||||
console.log(x);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return respuestasRegistradas;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all cuestionarioPrograma2`;
|
||||
async getCuestionario(dto: {version:string, year:string}) {
|
||||
const { version, year } = dto;
|
||||
const filePath = `server/uploads/${year}_cuestionario_programa.csv`;
|
||||
|
||||
let registros: any[];
|
||||
|
||||
if (version === 'v1') {
|
||||
registros = await this.cuestionarioRepo.find();
|
||||
|
||||
} else if (version === 'v2') {
|
||||
registros = await this.cuestionario2Repo.find();
|
||||
} else {
|
||||
throw new BadRequestException('Versión inválida');
|
||||
}
|
||||
|
||||
const data = registros.map((item) => ({ ...item }));
|
||||
|
||||
await this.archivoService.eliminarArchivo(filePath).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
return this.archivoService.crearArchivo(filePath, convertArrayToCSV(data));
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
|
||||
@@ -1 +1,142 @@
|
||||
export class CreateCuestionarioPrograma2Dto {}
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Length,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateCuestionarioPrograma2Dto {
|
||||
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
idServicio:number
|
||||
|
||||
|
||||
// p1, p2, p4, p5, p6
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 100)
|
||||
p1: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p2: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 100)
|
||||
p4: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 5)
|
||||
p5: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Length(1, 100)
|
||||
p6?: string;
|
||||
|
||||
// Sección p3_A
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_A_1: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_A_2: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_A_3: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_A_4: string;
|
||||
|
||||
// Sección p3_B
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_B_1: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_B_2: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_B_3: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_B_4: string;
|
||||
|
||||
// Sección p3_C
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_C_1: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_C_2: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_C_3: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_C_4: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_C_5: string;
|
||||
|
||||
// Sección p3_D
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_D_1: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_D_2: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_D_3: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_D_4: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_D_5: string;
|
||||
|
||||
// Sección p3_E
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(1, 50)
|
||||
p3_E_1: string;
|
||||
}
|
||||
|
||||
@@ -7,82 +7,82 @@ export class CuestionarioPrograma2 {
|
||||
idCuestionarioPrograma2: number;
|
||||
|
||||
// Sección p3_A_*
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_A_1: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_A_2: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_A_3: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_A_4: string;
|
||||
|
||||
// Sección p3_B_*
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_B_1: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_B_2: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_B_3: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_B_4: string;
|
||||
|
||||
// Sección p3_C_*
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_C_1: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_C_2: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_C_3: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_C_4: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_C_5: string;
|
||||
|
||||
// Sección p3_D_*
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_D_1: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_D_2: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_D_3: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_D_4: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_D_5: string;
|
||||
|
||||
// Sección p3_E_*
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p3_E_1: string;
|
||||
|
||||
// p1, p2, p4, p5, p6
|
||||
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||
@Column({ type: 'varchar', length: 100, nullable: false })
|
||||
p1: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
p2: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||
@Column({ type: 'varchar', length: 100, nullable: false })
|
||||
p4: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 5, nullable: true })
|
||||
@Column({ type: 'varchar', length: 5, nullable: false })
|
||||
p5: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||
p6: string;
|
||||
p6?: string;
|
||||
|
||||
@OneToMany(()=>Servicio,(servicio)=>servicio.cuestionarioAlumno2)
|
||||
servicio:Servicio[];
|
||||
|
||||
Reference in New Issue
Block a user