Se creo módulo de cuestionario programa
This commit is contained in:
@@ -1,21 +1,39 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { CuestionarioPrograma2Service } from './cuestionario-programa2.service';
|
||||
import { CreateCuestionarioPrograma2Dto } from './dto/create-cuestionario-programa2.dto';
|
||||
import { UpdateCuestionarioPrograma2Dto } from './dto/update-cuestionario-programa2.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { findCuestionarioProgama2Dto } from './dto/find.dto';
|
||||
|
||||
@Controller('cuestionario-programa2')
|
||||
export class CuestionarioPrograma2Controller {
|
||||
constructor(private readonly cuestionarioPrograma2Service: CuestionarioPrograma2Service) {}
|
||||
constructor(
|
||||
private readonly cuestionarioPrograma2Service: CuestionarioPrograma2Service,
|
||||
) {}
|
||||
|
||||
// @Post()
|
||||
// create(@Body() createCuestionarioPrograma2Dto: CreateCuestionarioPrograma2Dto) {
|
||||
// return this.cuestionarioPrograma2Service.create(createCuestionarioPrograma2Dto);
|
||||
// }
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
create(
|
||||
@Body() createCuestionarioPrograma2Dto: CreateCuestionarioPrograma2Dto,
|
||||
) {
|
||||
return this.cuestionarioPrograma2Service.create(
|
||||
createCuestionarioPrograma2Dto,
|
||||
);
|
||||
}
|
||||
|
||||
// @Get()
|
||||
// findAll() {
|
||||
// return this.cuestionarioPrograma2Service.findAll();
|
||||
// }
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
findAll(@Body() cuestionario: findCuestionarioProgama2Dto) {
|
||||
return this.cuestionarioPrograma2Service.getCuestionario(cuestionario);
|
||||
}
|
||||
|
||||
// @Get(':id')
|
||||
// findOne(@Param('id') id: string) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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';
|
||||
@@ -19,21 +18,27 @@ export class CuestionarioPrograma2Service {
|
||||
@InjectRepository(CuestionarioPrograma2)
|
||||
private cuestionario2Repo: Repository<CuestionarioPrograma2>,
|
||||
@InjectRepository(Servicio)
|
||||
private servicioRepository:Repository<Servicio>,
|
||||
private archivoService:ArchivoService,
|
||||
private validacionService:ValidacionService,
|
||||
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 cuestionario = this.validacionService.validarCuestionarioPrograma2(
|
||||
cuestionarioPrograma2,
|
||||
);
|
||||
|
||||
let servicio = await this.servicioRepository.findOne({where:{idServicio}});
|
||||
if(!servicio){
|
||||
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');
|
||||
if (servicio.cuestionarioPrograma2.idCuestionarioPrograma2) {
|
||||
throw new Error(
|
||||
'Este Servicio Social ya cuenta con cuestionario de alumno',
|
||||
);
|
||||
}
|
||||
|
||||
console.log('el servicio social si existe', servicio);
|
||||
@@ -42,39 +47,25 @@ export class CuestionarioPrograma2Service {
|
||||
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');
|
||||
|
||||
console.log("registrar id en servicio en cuestionario 2");
|
||||
|
||||
let x = await this.servicioRepository.update(
|
||||
|
||||
{ idServicio },
|
||||
{ cuestionarioPrograma2: respuestasRegistradas }
|
||||
)
|
||||
{ cuestionarioPrograma2: respuestasRegistradas },
|
||||
);
|
||||
|
||||
console.log(x);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return respuestasRegistradas;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getCuestionario(dto: {version:string, year:string}) {
|
||||
async getCuestionario(dto: { version: string; year: string }) {
|
||||
const { version, year } = dto;
|
||||
const filePath = `server/uploads/${year}_cuestionario_programa.csv`;
|
||||
|
||||
@@ -82,7 +73,6 @@ export class CuestionarioPrograma2Service {
|
||||
|
||||
if (version === 'v1') {
|
||||
registros = await this.cuestionarioRepo.find();
|
||||
|
||||
} else if (version === 'v2') {
|
||||
registros = await this.cuestionario2Repo.find();
|
||||
} else {
|
||||
@@ -97,5 +87,4 @@ export class CuestionarioPrograma2Service {
|
||||
|
||||
return this.archivoService.crearArchivo(filePath, convertArrayToCSV(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IsEnum, IsString, Length } from 'class-validator';
|
||||
|
||||
enum Version {
|
||||
ACTIVO = 'v1',
|
||||
INACTIVO = 'v2',
|
||||
}
|
||||
|
||||
export class findCuestionarioProgama2Dto {
|
||||
@IsEnum(Version, { 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;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateCuestionarioPrograma2Dto } from './create-cuestionario-programa2.dto';
|
||||
|
||||
export class UpdateCuestionarioPrograma2Dto extends PartialType(CreateCuestionarioPrograma2Dto) {}
|
||||
Reference in New Issue
Block a user