210 lines
7.3 KiB
TypeScript
210 lines
7.3 KiB
TypeScript
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags, getSchemaPath } from '@nestjs/swagger';
|
|
import { feriaSexualidad } from '../../utils/crear_formulario_feria';
|
|
import { applyDecorators } from '@nestjs/common';
|
|
import { FormularioDto, FormularioFeriaSchema } from './dto/formulario.schema';
|
|
|
|
export class CuestionarioApiDocumentation {
|
|
// Decoradores para toda la clase del controlador
|
|
static ApiController = ApiTags('Cuestionarios');
|
|
|
|
// Documentación para obtener el formulario completo
|
|
static ApiGetFormulario = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Obtener formulario completo',
|
|
description: 'Devuelve el cuestionario completo con la misma estructura que se usa para crearlo'
|
|
}),
|
|
ApiParam({
|
|
name: 'id',
|
|
description: 'ID del cuestionario',
|
|
required: true,
|
|
type: 'number',
|
|
example: 1
|
|
}),
|
|
ApiResponse({
|
|
status: 200,
|
|
description: 'Formulario completo con todas sus secciones, preguntas y opciones',
|
|
type: FormularioDto,
|
|
content: {
|
|
'application/json': {
|
|
schema: { $ref: getSchemaPath(FormularioDto) },
|
|
example: feriaSexualidad
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 404, description: 'Cuestionario no encontrado' })
|
|
);
|
|
|
|
// Documentación para crear un cuestionario
|
|
static ApiCreate = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Crear un nuevo cuestionario',
|
|
description: 'Crea un nuevo cuestionario con secciones, preguntas y opciones'
|
|
}),
|
|
ApiBody({
|
|
description: 'Datos del cuestionario a crear',
|
|
type: FormularioDto,
|
|
examples: {
|
|
feriaSexualidad: {
|
|
summary: 'Ejemplo de cuestionario para feria de sexualidad',
|
|
description: 'Cuestionario con secciones, preguntas y opciones para feria de sexualidad',
|
|
value: feriaSexualidad
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({
|
|
status: 201,
|
|
description: 'Cuestionario creado correctamente',
|
|
schema: {
|
|
properties: {
|
|
success: { type: 'boolean', example: true },
|
|
cuestionario: {
|
|
type: 'object',
|
|
properties: {
|
|
id_cuestionario: { type: 'number', example: 1 },
|
|
nombre_form: { type: 'string', example: 'Registro para la Feria de la Sexualidad - FES Acatlán' },
|
|
descripcion: { type: 'string' },
|
|
contador_secciones: { type: 'number', example: 1 },
|
|
editable: { type: 'boolean', example: true },
|
|
fecha_fin: { type: 'string', format: 'date-time' },
|
|
fecha_inicio: { type: 'string', format: 'date-time' },
|
|
id_tipo_cuestionario: { type: 'number', example: 1 }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 400, description: 'Datos del cuestionario inválidos' }),
|
|
ApiResponse({ status: 500, description: 'Error interno del servidor' })
|
|
);
|
|
|
|
// Documentación para obtener todos los cuestionarios
|
|
static ApiGetAll = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Obtener todos los cuestionarios',
|
|
description: 'Retorna una lista de todos los cuestionarios registrados'
|
|
}),
|
|
ApiResponse({
|
|
status: 200,
|
|
description: 'Lista de cuestionarios obtenida correctamente',
|
|
schema: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
id_cuestionario: { type: 'number', example: 1 },
|
|
nombre_form: { type: 'string', example: 'Registro para la Feria de la Sexualidad - FES Acatlán' },
|
|
descripcion: { type: 'string' },
|
|
contador_secciones: { type: 'number', example: 1 },
|
|
editable: { type: 'boolean', example: true },
|
|
fecha_fin: { type: 'string', format: 'date-time' },
|
|
fecha_inicio: { type: 'string', format: 'date-time' },
|
|
id_tipo_cuestionario: { type: 'number', example: 1 }
|
|
}
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 500, description: 'Error interno del servidor' })
|
|
);
|
|
|
|
// Documentación para obtener un cuestionario por ID
|
|
static ApiGetOne = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Obtener un cuestionario por ID',
|
|
description: 'Retorna un cuestionario específico por su ID'
|
|
}),
|
|
ApiParam({
|
|
name: 'id',
|
|
description: 'ID del cuestionario',
|
|
required: true,
|
|
type: 'number',
|
|
example: 1
|
|
}),
|
|
ApiResponse({
|
|
status: 200,
|
|
description: 'Cuestionario obtenido correctamente',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
id_cuestionario: { type: 'number', example: 1 },
|
|
nombre_form: { type: 'string', example: 'Registro para la Feria de la Sexualidad - FES Acatlán' },
|
|
descripcion: { type: 'string' },
|
|
contador_secciones: { type: 'number', example: 1 },
|
|
editable: { type: 'boolean', example: true },
|
|
fecha_fin: { type: 'string', format: 'date-time' },
|
|
fecha_inicio: { type: 'string', format: 'date-time' },
|
|
id_tipo_cuestionario: { type: 'number', example: 1 }
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 404, description: 'Cuestionario no encontrado' }),
|
|
ApiResponse({ status: 500, description: 'Error interno del servidor' })
|
|
);
|
|
|
|
// Documentación para actualizar un cuestionario
|
|
static ApiUpdate = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Actualizar un cuestionario',
|
|
description: 'Actualiza los datos de un cuestionario existente'
|
|
}),
|
|
ApiParam({
|
|
name: 'id',
|
|
description: 'ID del cuestionario a actualizar',
|
|
required: true,
|
|
type: 'number',
|
|
example: 1
|
|
}),
|
|
ApiBody({
|
|
description: 'Datos a actualizar del cuestionario',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
nombre_form: { type: 'string', example: 'Nombre actualizado del formulario' },
|
|
descripcion: { type: 'string', example: 'Descripción actualizada' },
|
|
fecha_inicio: { type: 'string', format: 'date-time' },
|
|
fecha_fin: { type: 'string', format: 'date-time' },
|
|
editable: { type: 'boolean', example: true }
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({
|
|
status: 200,
|
|
description: 'Cuestionario actualizado correctamente',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
affected: { type: 'number', example: 1 }
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 400, description: 'Datos de actualización inválidos' }),
|
|
ApiResponse({ status: 404, description: 'Cuestionario no encontrado' }),
|
|
ApiResponse({ status: 500, description: 'Error interno del servidor' })
|
|
);
|
|
|
|
// Documentación para eliminar un cuestionario
|
|
static ApiRemove = applyDecorators(
|
|
ApiOperation({
|
|
summary: 'Eliminar un cuestionario',
|
|
description: 'Elimina permanentemente un cuestionario por su ID'
|
|
}),
|
|
ApiParam({
|
|
name: 'id',
|
|
description: 'ID del cuestionario a eliminar',
|
|
required: true,
|
|
type: 'number',
|
|
example: 1
|
|
}),
|
|
ApiResponse({
|
|
status: 200,
|
|
description: 'Cuestionario eliminado correctamente',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
affected: { type: 'number', example: 1 }
|
|
}
|
|
}
|
|
}),
|
|
ApiResponse({ status: 404, description: 'Cuestionario no encontrado' }),
|
|
ApiResponse({ status: 500, description: 'Error interno del servidor' })
|
|
);
|
|
} |