diff --git a/src/Operations/operations.controller.ts b/src/Operations/operations.controller.ts index 0e01011..47b6bcf 100644 --- a/src/Operations/operations.controller.ts +++ b/src/Operations/operations.controller.ts @@ -2,33 +2,40 @@ import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common'; import { OperationsService } from './operations.services'; import { chargePrintDto } from './dto/operations.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('operations') export class OperationsController { - constructor(private readonly operationsService: OperationsService) {} + constructor(private readonly operationsService: OperationsService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL) @Post('impressions') async chargePrint(@Body() data: chargePrintDto, @Req() req: any) { const id_usuario = req.user.id; return this.operationsService.chargePrint(data, id_usuario); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL) @Post('receipt') async addCredit(@Body() data, @Req() req: any) { const id_usuario = req.user.id; return this.operationsService.addCredit(data, id_usuario); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS) @Post('registration') async addReceiptInscription(@Body() data, @Req() req: any) { const id_usuario = req.user.id; return this.operationsService.addReceiptInscription(data, id_usuario); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS) @Post('time') async addTime(@Body() data, @Req() req: any) { const id_usuario = req.user.id; diff --git a/src/alumno/student.controller.ts b/src/alumno/student.controller.ts index ac77915..4c298f4 100644 --- a/src/alumno/student.controller.ts +++ b/src/alumno/student.controller.ts @@ -11,31 +11,36 @@ import { Role } from 'src/role.enum'; export class AlumnoController { constructor(private readonly alumnoService: AlumnoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() async find() { return this.alumnoService.findAll() } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() async create(@Body() createStudentDto: CreateStudentDto): Promise { return this.alumnoService.create(createStudentDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA) @Get(':id') findOneWhitSancion(@Param('id') id: number) { return this.alumnoService.findOneWhitSancion(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA) @Get('sancion/:id') findOne(@Param('id') id: number) { return this.alumnoService.findOne(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('/create') async newStudent(@Body() createStudentDto: CreateStudentDto) { return this.alumnoService.create(createStudentDto); diff --git a/src/alumno_inscrito/alumno_inscrito.controller.ts b/src/alumno_inscrito/alumno_inscrito.controller.ts index 831ff31..ea012fb 100644 --- a/src/alumno_inscrito/alumno_inscrito.controller.ts +++ b/src/alumno_inscrito/alumno_inscrito.controller.ts @@ -5,36 +5,44 @@ import { } from './dto/create-alumno_inscrito.dto'; import { AlumnoInscrito } from './entities/alumno_inscrito.entity'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('alumno-inscrito') export class AlumnoInscritoController { constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Post() async create(@Body() dto: CreateAlumnoInscritoDto): Promise { return this.alumnoInscritoService.createWhitoutPay(dto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() async findAll(): Promise { return this.alumnoInscritoService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get("/inscritos/:idPeriodo") async findAllInscritos(@Param('idPeriodo') idPeriodo: number) { return this.alumnoInscritoService.findAllInscritos(idPeriodo); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/plataforma') async findAllPlataforma() { return this.alumnoInscritoService.findAllPlataforma(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get(':id_cuenta') async findByIdWhitoud( @Param('id_cuenta') id_cuenta: number, @@ -42,7 +50,8 @@ export class AlumnoInscritoController { return this.alumnoInscritoService.findByIdWhitoud(id_cuenta); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get(':id_cuenta/sancion') async findById( @Param('id_cuenta') id_cuenta: number, diff --git a/src/alumno_sancion/alumno_sancion.controller.ts b/src/alumno_sancion/alumno_sancion.controller.ts index 6aabdbd..938eeaa 100644 --- a/src/alumno_sancion/alumno_sancion.controller.ts +++ b/src/alumno_sancion/alumno_sancion.controller.ts @@ -2,24 +2,30 @@ import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/c import { AlumnoSancionService } from './alumno_sancion.service'; import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('alumno-sancion') export class AlumnoSancionController { constructor(private readonly alumnoSancionService: AlumnoSancionService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) { return this.alumnoSancionService.create(createAlumnoSancionDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findbyStudent(@Param('id') id: number) { return this.alumnoSancionService.findbyStudent(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Delete(':id_cuenta') async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) { return this.alumnoSancionService.removeByStudent(+id_cuenta); diff --git a/src/area_ubicacion/area_ubicacion.controller.ts b/src/area_ubicacion/area_ubicacion.controller.ts index 18615e2..5776f22 100644 --- a/src/area_ubicacion/area_ubicacion.controller.ts +++ b/src/area_ubicacion/area_ubicacion.controller.ts @@ -1,24 +1,30 @@ import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { AreaUbicacionService } from './area_ubicacion.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('area-ubicacion') export class AreaUbicacionController { constructor(private readonly areaUbicacionService: AreaUbicacionService) { } - @UseGuards(JwtAuthGuard) - @Get() + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) + @Get() findAll() { return this.areaUbicacionService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string) { return this.areaUbicacionService.findOne(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/programs/:id') findProgramsByArea(@Param('id') id: number) { return this.areaUbicacionService.findProgramsByArea(+id) diff --git a/src/bitacora/bitacora.controller.ts b/src/bitacora/bitacora.controller.ts index 593c68e..0fbb442 100644 --- a/src/bitacora/bitacora.controller.ts +++ b/src/bitacora/bitacora.controller.ts @@ -2,30 +2,37 @@ import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/co import { BitacoraService } from './bitacora.service'; import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('bitacora') export class BitacoraController { constructor(private readonly bitacoraService: BitacoraService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Post() assignment(@Body() createBitacoraDto: CreateBitacoraDto) { return this.bitacoraService.assignment(createBitacoraDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/cuenta/:id') findOneByAcount(@Param('id') id: string) { return this.bitacoraService.findOneByAcount(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/equipo/:id') findOneByMachine(@Param('id') id: string) { return this.bitacoraService.findOneByMachine(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Patch('cancelar/:id') cancelationByMachine( @Param('id') id: number, @@ -34,13 +41,15 @@ export class BitacoraController { return this.bitacoraService.cancelation(id, tiempo_asignado); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.bitacoraService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('equipos-por-dia') async obtenerEquipos( @Body() dto: BitacoraAlumnoDto @@ -51,7 +60,8 @@ export class BitacoraController { ); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('equipos-por-equipo') async equiposPorEquipo( @Body() dto: EquiposPorEquipoDto, diff --git a/src/bitacora_mesa/bitacora_mesa.controller.ts b/src/bitacora_mesa/bitacora_mesa.controller.ts index b5e3525..239ee32 100644 --- a/src/bitacora_mesa/bitacora_mesa.controller.ts +++ b/src/bitacora_mesa/bitacora_mesa.controller.ts @@ -10,48 +10,58 @@ import { import { BitacoraMesaService } from './bitacora_mesa.service'; import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('bitacora-mesa') export class BitacoraMesaController { constructor(private readonly bitacoraMesaService: BitacoraMesaService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Post() assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) { return this.bitacoraMesaService.assignment(createBitacoraMesaDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.bitacoraMesaService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string) { return this.bitacoraMesaService.findOne(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/cuenta/:id_cuenta') findByCuenta(@Param('id_cuenta') id_cuenta: string) { return this.bitacoraMesaService.findByCuenta(+id_cuenta); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/table/:id_mesa') findByTable(@Param('id_mesa') id_mesa: number) { return this.bitacoraMesaService.findByTable(id_mesa); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('/date') findByDate(@Body() data: FindByDate) { return this.bitacoraMesaService.findByDate(data.date); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Patch('cancelar/:id') cancelationByMachine( @Param('id') id: number, @@ -60,7 +70,8 @@ export class BitacoraMesaController { return this.bitacoraMesaService.cancelation(id, tiempo_asignado); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('mesas-por-dia') mesasPorDia(@Body() body: { fecha: string }) { return this.bitacoraMesaService.mesasPorFecha(body.fecha); diff --git a/src/carrera/carrera.controller.ts b/src/carrera/carrera.controller.ts index 4ab0e94..358f45a 100644 --- a/src/carrera/carrera.controller.ts +++ b/src/carrera/carrera.controller.ts @@ -2,12 +2,16 @@ import { Controller, Get, UseGuards } from '@nestjs/common'; import { CarreraService } from './carrera.service'; import { Carrera } from './entities/carrera.entity'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('carrera') export class CarreraController { constructor(private readonly carreraService: CarreraService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get() findAll(): Promise { return this.carreraService.findAll(); diff --git a/src/costo/costo.controller.ts b/src/costo/costo.controller.ts index 79c429b..c4299ae 100644 --- a/src/costo/costo.controller.ts +++ b/src/costo/costo.controller.ts @@ -1,18 +1,23 @@ import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { CostoService } from './costo.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Role } from 'src/role.enum'; +import { Roles } from 'src/roles.decorator'; @Controller('costo') export class CostoController { constructor(private readonly costoService: CostoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA) @Get() findAll() { return this.costoService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/:id_servicio') find(@Param('id_servicio') id_servicio: number) { return this.costoService.find(id_servicio); diff --git a/src/detalle_servicio/detalle_servicio.controller.ts b/src/detalle_servicio/detalle_servicio.controller.ts index 9158501..089ce3a 100644 --- a/src/detalle_servicio/detalle_servicio.controller.ts +++ b/src/detalle_servicio/detalle_servicio.controller.ts @@ -2,19 +2,24 @@ import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common'; import { DetalleServicioService } from './detalle_servicio.service'; import { FindReciboByRangeDto } from 'src/recibo/dto/create-recibo.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('detalle-servicio') export class DetalleServicioController { constructor(private readonly detalleServicioService: DetalleServicioService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.detalleServicioService.findAll() } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('rango') async findByDateRange(@Body() data: FindReciboByRangeDto) { return this.detalleServicioService.findByDateRange(data.desde, data.hasta); diff --git a/src/equipo/equipo.controller.ts b/src/equipo/equipo.controller.ts index 1d712e8..d1dc2e1 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -3,66 +3,79 @@ import { EquipoService } from './equipo.service'; import { Equipo } from './entities/equipo.entity'; import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('equipo') export class EquipoController { constructor(private readonly equipoService: EquipoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) @Get() + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) findAll(): Promise { return this.equipoService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/active') findActive() { return this.equipoService.findActive(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/disable') findDisable() { return this.equipoService.findDisable(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('/student/:id') findOnlyUsable(@Param('id') id: number): Promise { return this.equipoService.findOnlyUsable(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/busy') findOnlyBusy(): Promise { return this.equipoService.findOnlyBusy(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string): Promise { return this.equipoService.findOne(id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() create(@Body() equipo: CreateEquipoDto) { return this.equipoService.create(equipo); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch() update(@Body() equipo: CreateEquipoDto) { return this.equipoService.update(equipo); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) @Patch(':id/activo') toggleActivo(@Param('id') id: number) { return this.equipoService.toggleActivo(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Patch('actualizar-area') actualizarPorArea( @Body() updateAreaEquiposDto: UpdateAreaEquiposDto, diff --git a/src/mensaje/mensaje.controller.ts b/src/mensaje/mensaje.controller.ts index a74d627..1d4b0ea 100644 --- a/src/mensaje/mensaje.controller.ts +++ b/src/mensaje/mensaje.controller.ts @@ -1,18 +1,22 @@ import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { MensajeService } from './mensaje.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('mensaje') export class MensajeController { constructor(private readonly mensajeService: MensajeService) { } - @UseGuards(JwtAuthGuard) - @Get() + @UseGuards(JwtAuthGuard, RolesGuard) + @Get() @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) findAll() { return this.mensajeService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string) { return this.mensajeService.findOne(+id); diff --git a/src/mesa/mesa.controller.ts b/src/mesa/mesa.controller.ts index 356f17c..a713b76 100644 --- a/src/mesa/mesa.controller.ts +++ b/src/mesa/mesa.controller.ts @@ -2,30 +2,37 @@ import { Controller, Body, Patch, Param, Get, UseGuards } from '@nestjs/common'; import { MesaService } from './mesa.service'; import { UpdateMesaDto } from './dto/update-mesa.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Role } from 'src/role.enum'; +import { Roles } from 'src/roles.decorator'; @Controller('mesa') export class MesaController { constructor(private readonly mesaService: MesaService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get() async findAll() { return this.mesaService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('activo') async findAllActivo() { return this.mesaService.findAllActivo(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Get('uso') async findActiveMesas() { return this.mesaService.findActiveMesas(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch(':id') async updateActivo( @Param('id') id: number, @@ -34,7 +41,8 @@ export class MesaController { return this.mesaService.updateActivo(id, updateMesaDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) @Patch(':id/activo') toggleActivo(@Param('id') id: number) { return this.mesaService.toggleActivo(+id); diff --git a/src/periodo/periodo.controller.ts b/src/periodo/periodo.controller.ts index e57e60f..8d24838 100644 --- a/src/periodo/periodo.controller.ts +++ b/src/periodo/periodo.controller.ts @@ -2,27 +2,37 @@ import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } fro import { PeriodoService } from './periodo.service'; import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('periodo') export class PeriodoController { constructor(private readonly periodoService: PeriodoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.periodoService.findAll(); } + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() create(@Body() data: CreatePeriodoDto) { return this.periodoService.create(data); } + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Delete("/:id_periodo") delete(@Param("id_periodo") id_periodo: number) { return this.periodoService.delete(id_periodo) } + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch("/date/:id_periodo") modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) { return this.periodoService.modifiedDate(data, id_periodo) diff --git a/src/programa/programa.controller.ts b/src/programa/programa.controller.ts index 755afbf..cce6e19 100644 --- a/src/programa/programa.controller.ts +++ b/src/programa/programa.controller.ts @@ -2,36 +2,44 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@n import { ProgramaService } from './programa.service'; import { UpdateProgramaDto } from './dto/update-programa.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('programa') export class ProgramaController { constructor(private readonly programaService: ProgramaService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.programaService.findAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string) { return this.programaService.findOne(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() create(@Body() body) { return this.programaService.create(body); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch(':id') update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) { return this.programaService.update(+id, updateProgramaDto); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Delete(':id') delete(@Param('id') id:string){ return this.programaService.delete(+id); diff --git a/src/programa_equipo/programa_equipo.controller.ts b/src/programa_equipo/programa_equipo.controller.ts index c32fd8f..f7685e3 100644 --- a/src/programa_equipo/programa_equipo.controller.ts +++ b/src/programa_equipo/programa_equipo.controller.ts @@ -2,30 +2,38 @@ import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common'; import { ProgramaEquipoService } from './programa_equipo.service'; import { UpdateProgramaEquipoDto, UpdateProgramasSalaDto } from './dto/update-programa_equipo.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('programa-equipo') export class ProgramaEquipoController { - constructor(private readonly programaEquipoService: ProgramaEquipoService) {} + constructor(private readonly programaEquipoService: ProgramaEquipoService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('programas/:id') findAllProgramByNumber(@Param('id') id: number) { return this.programaEquipoService.findAllProgramByNumber(+id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) + @Get('ubicacion/:id') findAllProgramByUbicacion(@Param('id') id: string) { return this.programaEquipoService.findAllProgramByUbication(id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: string) { return this.programaEquipoService.findOne(id); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch('equipo/:id') updateMachine( @Param('id') id: string, @@ -37,7 +45,8 @@ export class ProgramaEquipoController { ); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch('sala') updateBySala(@Body() dto: UpdateProgramasSalaDto) { return this.programaEquipoService.updateBySala(dto.sala, dto.programas); diff --git a/src/recibo/recibo.controller.ts b/src/recibo/recibo.controller.ts index 74f3969..7fe36f4 100644 --- a/src/recibo/recibo.controller.ts +++ b/src/recibo/recibo.controller.ts @@ -3,17 +3,20 @@ import { Post, Body, UseGuards, - Req, } from '@nestjs/common'; import { ReciboService } from './recibo.service'; import { FindReciboByRangeDto } from './dto/create-recibo.dto'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('recibo') export class ReciboController { - constructor(private readonly reciboService: ReciboService) {} + constructor(private readonly reciboService: ReciboService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('rango') async findByDateRange(@Body() data: FindReciboByRangeDto) { return this.reciboService.findByDateRange(data.desde, data.hasta); diff --git a/src/role.enum.ts b/src/role.enum.ts index 3e7049b..2b858e1 100644 --- a/src/role.enum.ts +++ b/src/role.enum.ts @@ -1,5 +1,7 @@ - export enum Role { - ADMINISTRADOR = 'ADMINISTRADOR', - OPERADOR = 'OPERADOR', -} + ADMINISTRADOR = 1, + ATENCION_USUARIOS = 2, + SERVICIO_SOCIAL = 3, + SUPER_ADMINISTRADOR = 4, + PCPUMA = 5, +} \ No newline at end of file diff --git a/src/roles.guard.ts b/src/roles.guard.ts index a2c96e6..ecffd2d 100644 --- a/src/roles.guard.ts +++ b/src/roles.guard.ts @@ -6,7 +6,7 @@ import { ROLES_KEY } from './roles.decorator'; @Injectable() export class RolesGuard implements CanActivate { - constructor(private reflector: Reflector) {} + constructor(private reflector: Reflector) { } canActivate(context: ExecutionContext): boolean { const requiredRoles = this.reflector.getAllAndOverride(ROLES_KEY, [ @@ -17,6 +17,6 @@ export class RolesGuard implements CanActivate { return true; } const { user } = context.switchToHttp().getRequest(); - return requiredRoles.some((role) => user.role?.includes(role)); + return requiredRoles.some((role) => user.role === role); } } diff --git a/src/sancion/sancion.controller.ts b/src/sancion/sancion.controller.ts index c123b82..3545a60 100644 --- a/src/sancion/sancion.controller.ts +++ b/src/sancion/sancion.controller.ts @@ -1,17 +1,22 @@ import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { SancionService } from './sancion.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('sancion') export class SancionController { - constructor(private readonly sancionService: SancionService) {} + constructor(private readonly sancionService: SancionService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() find() { return this.sancionService.find(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get(':id') findOne(@Param('id') id: number) { return this.sancionService.findOne(+id); diff --git a/src/servicio/servicio.controller.ts b/src/servicio/servicio.controller.ts index 2a44f26..b8b6f32 100644 --- a/src/servicio/servicio.controller.ts +++ b/src/servicio/servicio.controller.ts @@ -1,12 +1,16 @@ import { Controller, Get, UseGuards } from '@nestjs/common'; import { ServicioService } from './servicio.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('servicio') export class ServicioController { - constructor(private readonly servicioService: ServicioService) {} + constructor(private readonly servicioService: ServicioService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() findAll() { return this.servicioService.findAll(); diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index e94f755..e6e1b9d 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -11,18 +11,23 @@ import type { Response } from 'express'; import { UserService } from './user.service'; import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto'; import { JwtAuthGuard } from './jwt.guard'; +import { RolesGuard } from 'src/roles.guard'; +import { Roles } from 'src/roles.decorator'; +import { Role } from 'src/role.enum'; @Controller('user') export class UserController { - constructor(private readonly userService: UserService) {} + constructor(private readonly userService: UserService) { } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get() async getAll() { return this.userService.getAll(); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Get('/perfil') async getAllPerfil() { return this.userService.getAllPerfil(); @@ -39,13 +44,15 @@ export class UserController { return req.user.role; } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('/create') async createUser(@Body() data: CreateUserDto) { return this.userService.create(data); } - @UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post('/changePassword') async changePassword(@Body() data: changePasswordDto, @Req() req) { const id_usuario = req.user.id;