Files
formularios_api/src/pregunta/pregunta.documentation.ts
T

249 lines
7.7 KiB
TypeScript
Raw Normal View History

2025-06-13 22:41:20 -06:00
import {
ApiBody,
ApiOperation,
ApiParam,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
2025-04-02 11:50:08 -06:00
import { applyDecorators } from '@nestjs/common';
2025-06-13 22:41:20 -06:00
import { TipoPreguntaEnum } from 'src/tipo_pregunta/entities/tipo_pregunta.entity';
2025-04-02 11:50:08 -06:00
export class PreguntaApiDocumentation {
// Decoradores para toda la clase del controlador
static ApiController = ApiTags('Preguntas');
// Documentación para crear una pregunta
static ApiCreate = applyDecorators(
ApiOperation({
summary: 'Crear una nueva pregunta',
2025-06-13 22:41:20 -06:00
description: 'Crea una nueva pregunta para una sección',
2025-04-02 11:50:08 -06:00
}),
ApiBody({
description: 'Datos de la pregunta a crear',
schema: {
type: 'object',
required: ['titulo', 'tipo'],
properties: {
titulo: { type: 'string', example: '¿Eres parte de la comunidad?' },
obligatoria: { type: 'boolean', example: true },
2025-06-13 22:41:20 -06:00
tipo: {
type: 'string',
enum: Object.values(TipoPreguntaEnum),
2025-06-13 22:41:20 -06:00
description:
'Tipo de pregunta: Cerrada (opción única), Abierta (texto libre), Multiple (varias opciones)',
example: TipoPreguntaEnum.Cerrada,
},
2025-04-02 11:50:08 -06:00
contador_opcion: { type: 'number', example: 0 },
2025-06-13 22:41:20 -06:00
validacion: {
type: 'string',
description:
'Tipo de validación para la respuesta (cuenta_alumno, correo, telefono, nombre, entero, decimal, etc)',
example: 'correo',
},
2025-04-02 11:50:08 -06:00
opciones: {
type: 'array',
items: {
type: 'object',
properties: {
2025-06-13 22:41:20 -06:00
valor: { type: 'string', example: 'Si' },
},
},
},
},
},
examples: {
cerrada: {
summary: 'Pregunta de opción única',
value: {
titulo: '¿Eres parte de la comunidad de la FES Acatlán?',
obligatoria: true,
2025-06-13 22:41:20 -06:00
tipo: TipoPreguntaEnum.Cerrada,
validacion: null,
2025-06-13 22:41:20 -06:00
opciones: [{ valor: 'Sí' }, { valor: 'No' }],
},
},
abierta: {
summary: 'Pregunta de texto libre',
value: {
titulo: '¿Qué mejorarías en nuestro servicio?',
obligatoria: false,
2025-06-13 22:41:20 -06:00
tipo: TipoPreguntaEnum.AbiertaParrafo,
validacion: null,
},
},
multiple: {
summary: 'Pregunta de selección múltiple',
value: {
titulo: '¿Qué aspectos del servicio fueron de tu agrado?',
obligatoria: false,
2025-06-13 22:41:20 -06:00
tipo: TipoPreguntaEnum.Multiple,
validacion: null,
opciones: [
{ valor: 'Rapidez' },
{ valor: 'Atención al cliente' },
2025-06-13 22:41:20 -06:00
{ valor: 'Facilidad de uso' },
],
},
},
},
}),
ApiResponse({
status: 201,
2025-04-02 11:50:08 -06:00
description: 'Pregunta creada correctamente',
schema: {
type: 'object',
properties: {
id_pregunta: { type: 'number', example: 1 },
pregunta: { type: 'string', example: '¿Eres parte de la comunidad?' },
obligatoria: { type: 'boolean', example: true },
contador_opcion: { type: 'number', example: 0 },
id_tipo_pregunta: { type: 'number', example: 1 },
2025-06-13 22:41:20 -06:00
validacion: { type: 'string', example: 'correo' },
},
},
2025-04-02 11:50:08 -06:00
}),
ApiResponse({ status: 400, description: 'Datos de la pregunta inválidos' }),
2025-06-13 22:41:20 -06:00
ApiResponse({ status: 500, description: 'Error interno del servidor' }),
2025-04-02 11:50:08 -06:00
);
// Documentación para obtener todas las preguntas
static ApiGetAll = applyDecorators(
ApiOperation({
summary: 'Obtener todas las preguntas',
2025-06-13 22:41:20 -06:00
description: 'Retorna una lista de todas las preguntas registradas',
2025-04-02 11:50:08 -06:00
}),
ApiResponse({
status: 200,
description: 'Lista de preguntas obtenida correctamente',
schema: {
type: 'array',
items: {
type: 'object',
properties: {
id_pregunta: { type: 'number', example: 1 },
2025-06-13 22:41:20 -06:00
pregunta: {
type: 'string',
example: '¿Eres parte de la comunidad?',
},
2025-04-02 11:50:08 -06:00
obligatoria: { type: 'boolean', example: true },
contador_opcion: { type: 'number', example: 0 },
id_tipo_pregunta: { type: 'number', example: 1 },
2025-06-13 22:41:20 -06:00
validacion: { type: 'string', example: 'correo' },
},
},
},
2025-04-02 11:50:08 -06:00
}),
2025-06-13 22:41:20 -06:00
ApiResponse({ status: 500, description: 'Error interno del servidor' }),
2025-04-02 11:50:08 -06:00
);
// Documentación para obtener una pregunta por ID
static ApiGetOne = applyDecorators(
ApiOperation({
summary: 'Obtener una pregunta por ID',
2025-06-13 22:41:20 -06:00
description: 'Retorna una pregunta específica por su ID',
2025-04-02 11:50:08 -06:00
}),
ApiParam({
name: 'id',
description: 'ID de la pregunta',
required: true,
type: 'number',
2025-06-13 22:41:20 -06:00
example: 1,
2025-04-02 11:50:08 -06:00
}),
ApiResponse({
status: 200,
description: 'Pregunta obtenida correctamente',
schema: {
type: 'object',
properties: {
id_pregunta: { type: 'number', example: 1 },
pregunta: { type: 'string', example: '¿Eres parte de la comunidad?' },
obligatoria: { type: 'boolean', example: true },
contador_opcion: { type: 'number', example: 0 },
id_tipo_pregunta: { type: 'number', example: 1 },
validacion: { type: 'string', example: 'correo' },
2025-04-02 11:50:08 -06:00
opciones: {
type: 'array',
items: {
type: 'object',
properties: {
id_opcion: { type: 'number', example: 1 },
2025-06-13 22:41:20 -06:00
opcion: { type: 'string', example: 'Si' },
},
},
},
},
},
2025-04-02 11:50:08 -06:00
}),
ApiResponse({ status: 404, description: 'Pregunta no encontrada' }),
2025-06-13 22:41:20 -06:00
ApiResponse({ status: 500, description: 'Error interno del servidor' }),
2025-04-02 11:50:08 -06:00
);
// Documentación para actualizar una pregunta
static ApiUpdate = applyDecorators(
ApiOperation({
summary: 'Actualizar una pregunta',
2025-06-13 22:41:20 -06:00
description: 'Actualiza los datos de una pregunta existente',
2025-04-02 11:50:08 -06:00
}),
ApiParam({
name: 'id',
description: 'ID de la pregunta a actualizar',
required: true,
type: 'number',
2025-06-13 22:41:20 -06:00
example: 1,
2025-04-02 11:50:08 -06:00
}),
ApiBody({
description: 'Datos a actualizar de la pregunta',
schema: {
type: 'object',
properties: {
pregunta: { type: 'string', example: 'Pregunta actualizada' },
2025-06-13 22:41:20 -06:00
obligatoria: { type: 'boolean', example: false },
},
},
2025-04-02 11:50:08 -06:00
}),
ApiResponse({
status: 200,
description: 'Pregunta actualizada correctamente',
schema: {
type: 'object',
properties: {
2025-06-13 22:41:20 -06:00
affected: { type: 'number', example: 1 },
},
},
}),
ApiResponse({
status: 400,
description: 'Datos de actualización inválidos',
2025-04-02 11:50:08 -06:00
}),
ApiResponse({ status: 404, description: 'Pregunta no encontrada' }),
2025-06-13 22:41:20 -06:00
ApiResponse({ status: 500, description: 'Error interno del servidor' }),
2025-04-02 11:50:08 -06:00
);
// Documentación para eliminar una pregunta
static ApiRemove = applyDecorators(
ApiOperation({
summary: 'Eliminar una pregunta',
2025-06-13 22:41:20 -06:00
description: 'Elimina permanentemente una pregunta por su ID',
2025-04-02 11:50:08 -06:00
}),
ApiParam({
name: 'id',
description: 'ID de la pregunta a eliminar',
required: true,
type: 'number',
2025-06-13 22:41:20 -06:00
example: 1,
2025-04-02 11:50:08 -06:00
}),
ApiResponse({
status: 200,
description: 'Pregunta eliminada correctamente',
schema: {
type: 'object',
properties: {
2025-06-13 22:41:20 -06:00
affected: { type: 'number', example: 1 },
},
},
2025-04-02 11:50:08 -06:00
}),
ApiResponse({ status: 404, description: 'Pregunta no encontrada' }),
2025-06-13 22:41:20 -06:00
ApiResponse({ status: 500, description: 'Error interno del servidor' }),
2025-04-02 11:50:08 -06:00
);
2025-06-13 22:41:20 -06:00
}