115 lines
2.9 KiB
TypeScript
115 lines
2.9 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { OperadorService } from './operador.service';
|
|
import { OperadorCreateDto } from './dto/operador-create.dto';
|
|
import { OperadorOperadoresDto } from './dto/operador-operadores.dto';
|
|
import { OperadorUpdateDto } from './dto/operador-update.dto';
|
|
import { OperadorDto } from './dto/operador.dto';
|
|
|
|
@Controller('operador')
|
|
@ApiTags('operador')
|
|
export class OperadorController {
|
|
constructor(private operadorService: OperadorService) {}
|
|
|
|
@Post()
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({ description: 'Endpoint que crea un operador.' })
|
|
@ApiBody({
|
|
description: 'Todas las variables son obligatorias.',
|
|
examples: {
|
|
ejemplo: {
|
|
value: {
|
|
id_institucion: 200,
|
|
id_tipo_usuario: 4,
|
|
operador: '',
|
|
password: '',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
create(@Body() body: OperadorCreateDto) {
|
|
return this.operadorService.create(
|
|
body.id_institucion,
|
|
body.id_tipo_usuario,
|
|
body.operador,
|
|
body.password,
|
|
);
|
|
}
|
|
|
|
@Get('operador')
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({
|
|
description: 'Endpoint que retorna la información de un operador.',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id del operador.',
|
|
name: 'id_operador',
|
|
type: 'string',
|
|
})
|
|
operador(@Query() query: OperadorDto) {
|
|
return this.operadorService.findById(parseInt(query.id_operador));
|
|
}
|
|
|
|
@Get('operadores')
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({
|
|
description:
|
|
'Endpoint que retorna 25 operadores dependiendo de la página en la que se encuentra el usuario y sus filtros.',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Página en la que se encuentra el usuario.',
|
|
name: 'pagina',
|
|
type: 'string',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id de la institución que se queire usar como filtro.',
|
|
name: 'id_institucion',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id del tipo usuario que se queire usar como filtro.',
|
|
name: 'id_tipo_usuario',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Operador que se queire buscar.',
|
|
name: 'operador',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
operadores(@Query() query: OperadorOperadoresDto) {
|
|
return this.operadorService.findAll(query);
|
|
}
|
|
|
|
// @Get('reporte')
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
// reporte() {}
|
|
|
|
@Put()
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({
|
|
description: 'Endpoint que actualiza la información de un operador.',
|
|
})
|
|
@ApiBody({
|
|
description:
|
|
'Todas las variables a excepción de id_operador son opcionales.',
|
|
examples: {
|
|
ejemplo: { value: { id_operador: 3, activo: true, password: '' } },
|
|
},
|
|
})
|
|
update(@Body() body: OperadorUpdateDto) {
|
|
return this.operadorService.update(body);
|
|
}
|
|
}
|