cuestionario contestado, respuestas guardadas
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags, getSchemaPath } from '@nestjs/swagger';
|
||||
import { feriaSexualidad } from '../../utils/crear_formulario_feria';
|
||||
import { applyDecorators } from '@nestjs/common';
|
||||
import { FormularioDto } from './dto/formulario.schema';
|
||||
import { FormularioDto, FormularioFeriaSchema } from './dto/formulario.schema';
|
||||
|
||||
export class CuestionarioApiDocumentation {
|
||||
// Decoradores para toda la clase del controlador
|
||||
|
||||
@@ -79,15 +79,22 @@ export class CuestionarioService {
|
||||
for (let j = 0; j < seccionDto.preguntas.length; j++) {
|
||||
const preguntaDto = seccionDto.preguntas[j];
|
||||
|
||||
// Obtener el tipo de pregunta por su nombre
|
||||
const tipoPregunta = await queryRunner.manager.findOne(TipoPregunta, {
|
||||
where: { tipo_pregunta: preguntaDto.tipo },
|
||||
});
|
||||
// Mapear directamente el tipo de pregunta a su ID correspondiente
|
||||
let idTipoPregunta = 7; // Valor por defecto (desconocido)
|
||||
|
||||
if (!tipoPregunta) {
|
||||
throw new Error(`Tipo de pregunta '${preguntaDto.tipo}' no encontrado`);
|
||||
// Mapeamos el tipo de pregunta a su ID correspondiente
|
||||
if (preguntaDto.tipo === 'Cerrada') {
|
||||
idTipoPregunta = 1;
|
||||
} else if (preguntaDto.tipo === 'Abierta') {
|
||||
idTipoPregunta = 2;
|
||||
} else if (preguntaDto.tipo === 'Multiple') {
|
||||
idTipoPregunta = 3;
|
||||
} else {
|
||||
console.warn(`Tipo de pregunta no reconocido: ${preguntaDto.tipo}. Se asignará como desconocido.`);
|
||||
}
|
||||
|
||||
const tipoPregunta = { id_tipo: idTipoPregunta, tipo_pregunta: preguntaDto.tipo };
|
||||
|
||||
// Crear pregunta
|
||||
const pregunta = new Pregunta();
|
||||
pregunta.pregunta = preguntaDto.titulo;
|
||||
@@ -179,6 +186,13 @@ export class CuestionarioService {
|
||||
tipo_cuestionario: 'Encuesta'
|
||||
};
|
||||
|
||||
// Mapeador de ID de tipo de pregunta a nombres conocidos
|
||||
const tiposPreguntaMap = {
|
||||
1: { id_tipo: 1, tipo_pregunta: 'Cerrada' },
|
||||
2: { id_tipo: 2, tipo_pregunta: 'Abierta' },
|
||||
3: { id_tipo: 3, tipo_pregunta: 'Multiple' }
|
||||
};
|
||||
|
||||
// Obtener las relaciones cuestionario-seccion
|
||||
const cuestionarioSecciones = await this.cuestionarioSeccionRepository.find({
|
||||
where: { id_cuestionario: id },
|
||||
@@ -216,14 +230,8 @@ export class CuestionarioService {
|
||||
|
||||
if (!pregunta) return null;
|
||||
|
||||
// Usar un mapeo hardcodeado para tipos de pregunta
|
||||
const tiposPregunta = {
|
||||
1: { id_tipo: 1, tipo_pregunta: 'Cerrada' },
|
||||
2: { id_tipo: 2, tipo_pregunta: 'Abierta' },
|
||||
3: { id_tipo: 3, tipo_pregunta: 'Multiple' }
|
||||
};
|
||||
|
||||
const tipoPregunta = tiposPregunta[pregunta.id_tipo_pregunta] ||
|
||||
// Usar el mapeo de tipos de pregunta definido arriba
|
||||
const tipoPregunta = tiposPreguntaMap[pregunta.id_tipo_pregunta] ||
|
||||
{ id_tipo: pregunta.id_tipo_pregunta, tipo_pregunta: 'Desconocido' };
|
||||
|
||||
// Obtener opciones para preguntas de tipo multiple/radio
|
||||
|
||||
@@ -1,94 +1,198 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { TipoPreguntaEnum } from '../../pregunta/dto/create-pregunta.dto';
|
||||
|
||||
export class OpcionDto {
|
||||
@ApiProperty({
|
||||
description: 'Valor de la opción',
|
||||
example: 'Si'
|
||||
})
|
||||
valor: string;
|
||||
}
|
||||
|
||||
export class PreguntaDto {
|
||||
@ApiProperty({
|
||||
description: 'Título de la pregunta',
|
||||
example: '¿Eres parte de la comunidad de la FES Acatlán?'
|
||||
})
|
||||
titulo: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Indica si la pregunta es obligatoria',
|
||||
example: true
|
||||
})
|
||||
obligatoria: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Tipo de pregunta (Texto, Numero, Multiple, Radio, Abierto, Fecha)',
|
||||
example: 'Multiple'
|
||||
})
|
||||
tipo: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Lista de opciones para preguntas de tipo Multiple o Radio',
|
||||
type: [OpcionDto],
|
||||
required: false
|
||||
})
|
||||
opciones?: OpcionDto[];
|
||||
}
|
||||
|
||||
export class SeccionDto {
|
||||
@ApiProperty({
|
||||
description: 'Título de la sección',
|
||||
example: 'Información Personal'
|
||||
})
|
||||
titulo: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Descripción de la sección',
|
||||
example: 'Proporciona tus datos personales para poder contactarte.'
|
||||
})
|
||||
descripcion?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Lista de preguntas que conforman la sección',
|
||||
type: [PreguntaDto]
|
||||
})
|
||||
preguntas: PreguntaDto[];
|
||||
}
|
||||
// Ejemplo de respuesta de cuestionario completo
|
||||
export const FormularioFeriaSchema = {
|
||||
tipo_cuestionario: {
|
||||
id_tipo_cuestionario: 1,
|
||||
tipo_cuestionario: 'Encuesta'
|
||||
},
|
||||
cuestionario: {
|
||||
id_cuestionario: 10,
|
||||
nombre_form: 'Registro para la Feria de la Sexualidad - Comunidad FES Acatlán',
|
||||
contador_secciones: 2,
|
||||
descripcion: 'La Feria de la Sexualidad es un espacio seguro e informativo dirigido a toda la comunidad universitaria. Este registro nos ayudará a organizar mejor las actividades, talleres y charlas, así como conocer tus intereses. Por favor, completa el siguiente formulario para confirmar tu participación.',
|
||||
editable: true,
|
||||
fecha_inicio: '2025-03-26T00:00:00',
|
||||
fecha_fin: '2025-03-31T23:59:59',
|
||||
id_cuestionario_original: null,
|
||||
id_tipo_cuestionario: 1,
|
||||
secciones: [
|
||||
{
|
||||
id_cuestionario_seccion: 1,
|
||||
posicion: 1,
|
||||
seccion: {
|
||||
id_seccion: 100,
|
||||
contador_pregunta: 2,
|
||||
descripcion: 'Información básica',
|
||||
titulo: 'Datos personales'
|
||||
},
|
||||
preguntas: [
|
||||
{
|
||||
id_seccion_pregunta: 1000,
|
||||
posicion: 1,
|
||||
pregunta: {
|
||||
id_pregunta: 101,
|
||||
pregunta: '¿Eres parte de la comunidad de la FES Acatlán?',
|
||||
contador_opcion: 2,
|
||||
obligatoria: true,
|
||||
id_tipo_pregunta: 1,
|
||||
id_opcion_dependiente: null,
|
||||
tipo_pregunta: {
|
||||
id_tipo: 1,
|
||||
tipo_pregunta: 'Cerrada'
|
||||
},
|
||||
opciones: [
|
||||
{
|
||||
id_pregunta_opcion: 50001,
|
||||
posicion: 1,
|
||||
id_opcion: 90001,
|
||||
opcion: {
|
||||
id_opcion: 90001,
|
||||
opcion: 'Sí'
|
||||
}
|
||||
},
|
||||
{
|
||||
id_pregunta_opcion: 50002,
|
||||
posicion: 2,
|
||||
id_opcion: 90002,
|
||||
opcion: {
|
||||
id_opcion: 90002,
|
||||
opcion: 'No'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id_seccion_pregunta: 1001,
|
||||
posicion: 2,
|
||||
pregunta: {
|
||||
id_pregunta: 102,
|
||||
pregunta: 'Número de cuenta (solo para estudiantes de la FES Acatlán)',
|
||||
contador_opcion: 0,
|
||||
obligatoria: false,
|
||||
id_tipo_pregunta: 2,
|
||||
id_opcion_dependiente: 90001, // Dependiente de la respuesta "Sí" en la pregunta anterior
|
||||
tipo_pregunta: {
|
||||
id_tipo: 2,
|
||||
tipo_pregunta: 'Abierta'
|
||||
},
|
||||
opciones: []
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id_cuestionario_seccion: 2,
|
||||
posicion: 2,
|
||||
seccion: {
|
||||
id_seccion: 101,
|
||||
contador_pregunta: 2,
|
||||
descripcion: 'Información sobre tus intereses',
|
||||
titulo: 'Intereses'
|
||||
},
|
||||
preguntas: [
|
||||
{
|
||||
id_seccion_pregunta: 1003,
|
||||
posicion: 1,
|
||||
pregunta: {
|
||||
id_pregunta: 106,
|
||||
pregunta: '¿Qué temas te interesan para la Feria de la Sexualidad?',
|
||||
contador_opcion: 5,
|
||||
obligatoria: true,
|
||||
id_tipo_pregunta: 3,
|
||||
id_opcion_dependiente: null,
|
||||
tipo_pregunta: {
|
||||
id_tipo: 3,
|
||||
tipo_pregunta: 'Multiple'
|
||||
},
|
||||
opciones: [
|
||||
{
|
||||
id_pregunta_opcion: 50010,
|
||||
posicion: 1,
|
||||
id_opcion: 90010,
|
||||
opcion: {
|
||||
id_opcion: 90010,
|
||||
opcion: 'Educación sexual'
|
||||
}
|
||||
},
|
||||
{
|
||||
id_pregunta_opcion: 50011,
|
||||
posicion: 2,
|
||||
id_opcion: 90011,
|
||||
opcion: {
|
||||
id_opcion: 90011,
|
||||
opcion: 'Prevención de ITS'
|
||||
}
|
||||
},
|
||||
{
|
||||
id_pregunta_opcion: 50012,
|
||||
posicion: 3,
|
||||
id_opcion: 90012,
|
||||
opcion: {
|
||||
id_opcion: 90012,
|
||||
opcion: 'Salud reproductiva'
|
||||
}
|
||||
},
|
||||
{
|
||||
id_pregunta_opcion: 50013,
|
||||
posicion: 4,
|
||||
id_opcion: 90013,
|
||||
opcion: {
|
||||
id_opcion: 90013,
|
||||
opcion: 'Diversidad sexual y de género'
|
||||
}
|
||||
},
|
||||
{
|
||||
id_pregunta_opcion: 50014,
|
||||
posicion: 5,
|
||||
id_opcion: 90014,
|
||||
opcion: {
|
||||
id_opcion: 90014,
|
||||
opcion: 'Relaciones saludables'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id_seccion_pregunta: 1004,
|
||||
posicion: 2,
|
||||
pregunta: {
|
||||
id_pregunta: 107,
|
||||
pregunta: '¿Algún otro tema que te gustaría que se abordara?',
|
||||
contador_opcion: 0,
|
||||
obligatoria: false,
|
||||
id_tipo_pregunta: 2,
|
||||
id_opcion_dependiente: null,
|
||||
tipo_pregunta: {
|
||||
id_tipo: 2,
|
||||
tipo_pregunta: 'Abierta'
|
||||
},
|
||||
opciones: []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
// Ejemplo de tipo FormularioDto para usar en la API
|
||||
export class FormularioDto {
|
||||
@ApiProperty({
|
||||
description: 'Nombre del formulario',
|
||||
example: 'Registro para la Feria de la Sexualidad - FES Acatlán'
|
||||
description: 'Tipo de cuestionario',
|
||||
example: {
|
||||
id_tipo_cuestionario: 1,
|
||||
tipo_cuestionario: 'Encuesta'
|
||||
}
|
||||
})
|
||||
nombre_form: string;
|
||||
tipo_cuestionario: any;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Descripción del formulario',
|
||||
example: 'La Feria de la Sexualidad es un espacio seguro e informativo...'
|
||||
description: 'Información completa del cuestionario',
|
||||
example: FormularioFeriaSchema.cuestionario
|
||||
})
|
||||
descripcion?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Fecha de inicio del formulario',
|
||||
example: '2025-03-07T00:00:01'
|
||||
})
|
||||
fecha_inicio?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Fecha de fin del formulario',
|
||||
example: '2025-03-18T23:59:59'
|
||||
})
|
||||
fecha_fin?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ID del tipo de cuestionario',
|
||||
example: 1
|
||||
})
|
||||
id_tipo_cuestionario: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Secciones que conforman el formulario',
|
||||
type: [SeccionDto]
|
||||
})
|
||||
secciones: SeccionDto[];
|
||||
cuestionario: any;
|
||||
}
|
||||
Reference in New Issue
Block a user