cuestionario contestado, respuestas guardadas
This commit is contained in:
@@ -1,33 +1,93 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsArray, IsBoolean, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested } from 'class-validator';
|
||||
import { IsArray, IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export enum TipoPreguntaEnum {
|
||||
CERRADA = 'Cerrada',
|
||||
ABIERTA = 'Abierta',
|
||||
MULTIPLE = 'Multiple'
|
||||
}
|
||||
|
||||
export class OpcionDto {
|
||||
@ApiProperty({
|
||||
description: 'Valor de la opción',
|
||||
example: 'Sí'
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
valor: string;
|
||||
}
|
||||
|
||||
export class CreatePreguntaDto {
|
||||
@ApiProperty({
|
||||
description: 'Título o texto de la pregunta',
|
||||
example: '¿Eres parte de la comunidad de la FES Acatlán?'
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
titulo: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Indica si la pregunta es obligatoria',
|
||||
example: true,
|
||||
default: false
|
||||
})
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
obligatoria?: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Tipo de pregunta',
|
||||
enum: Object.values(TipoPreguntaEnum),
|
||||
enumName: 'TipoPreguntaEnum',
|
||||
example: TipoPreguntaEnum.CERRADA,
|
||||
examples: {
|
||||
'cerrada': {
|
||||
summary: 'Pregunta de opción única',
|
||||
value: TipoPreguntaEnum.CERRADA
|
||||
},
|
||||
'abierta': {
|
||||
summary: 'Pregunta de texto libre',
|
||||
value: TipoPreguntaEnum.ABIERTA
|
||||
},
|
||||
'multiple': {
|
||||
summary: 'Pregunta de selección múltiple',
|
||||
value: TipoPreguntaEnum.MULTIPLE
|
||||
}
|
||||
}
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@IsEnum(TipoPreguntaEnum, {
|
||||
message: 'El tipo debe ser uno de los siguientes valores: Cerrada, Abierta, Multiple'
|
||||
})
|
||||
tipo: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Contador de opciones (se calcula automáticamente)',
|
||||
required: false
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
contador_opcion?: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ID de la opción de la que depende esta pregunta (para preguntas condicionadas)',
|
||||
required: false,
|
||||
example: null
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
id_opcion_dependiente?: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Lista de opciones para preguntas de tipo Cerrada o Multiple',
|
||||
type: [OpcionDto],
|
||||
required: false,
|
||||
examples: [
|
||||
{ valor: 'Sí' },
|
||||
{ valor: 'No' }
|
||||
]
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { applyDecorators } from '@nestjs/common';
|
||||
import { TipoPreguntaEnum } from './dto/create-pregunta.dto';
|
||||
|
||||
export class PreguntaApiDocumentation {
|
||||
// Decoradores para toda la clase del controlador
|
||||
@@ -19,7 +20,12 @@ export class PreguntaApiDocumentation {
|
||||
properties: {
|
||||
titulo: { type: 'string', example: '¿Eres parte de la comunidad?' },
|
||||
obligatoria: { type: 'boolean', example: true },
|
||||
tipo: { type: 'string', example: 'Multiple' },
|
||||
tipo: {
|
||||
type: 'string',
|
||||
enum: Object.values(TipoPreguntaEnum),
|
||||
description: 'Tipo de pregunta: Cerrada (opción única), Abierta (texto libre), Multiple (varias opciones)',
|
||||
example: TipoPreguntaEnum.CERRADA
|
||||
},
|
||||
contador_opcion: { type: 'number', example: 0 },
|
||||
id_opcion_dependiente: { type: 'number', example: null },
|
||||
opciones: {
|
||||
@@ -32,6 +38,41 @@ export class PreguntaApiDocumentation {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
examples: {
|
||||
cerrada: {
|
||||
summary: 'Pregunta de opción única',
|
||||
value: {
|
||||
titulo: '¿Eres parte de la comunidad de la FES Acatlán?',
|
||||
obligatoria: true,
|
||||
tipo: TipoPreguntaEnum.CERRADA,
|
||||
opciones: [
|
||||
{ valor: 'Sí' },
|
||||
{ valor: 'No' }
|
||||
]
|
||||
}
|
||||
},
|
||||
abierta: {
|
||||
summary: 'Pregunta de texto libre',
|
||||
value: {
|
||||
titulo: '¿Qué mejorarías en nuestro servicio?',
|
||||
obligatoria: false,
|
||||
tipo: TipoPreguntaEnum.ABIERTA
|
||||
}
|
||||
},
|
||||
multiple: {
|
||||
summary: 'Pregunta de selección múltiple',
|
||||
value: {
|
||||
titulo: '¿Qué aspectos del servicio fueron de tu agrado?',
|
||||
obligatoria: false,
|
||||
tipo: TipoPreguntaEnum.MULTIPLE,
|
||||
opciones: [
|
||||
{ valor: 'Rapidez' },
|
||||
{ valor: 'Atención al cliente' },
|
||||
{ valor: 'Facilidad de uso' }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
ApiResponse({
|
||||
|
||||
Reference in New Issue
Block a user