added all roles

This commit is contained in:
2026-03-02 14:49:15 -06:00
parent 8aa0eab353
commit 0323c93ca3
22 changed files with 233 additions and 92 deletions
+12 -5
View File
@@ -2,33 +2,40 @@ import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
import { OperationsService } from './operations.services'; import { OperationsService } from './operations.services';
import { chargePrintDto } from './dto/operations.dto'; import { chargePrintDto } from './dto/operations.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('operations')
export class OperationsController { 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') @Post('impressions')
async chargePrint(@Body() data: chargePrintDto, @Req() req: any) { async chargePrint(@Body() data: chargePrintDto, @Req() req: any) {
const id_usuario = req.user.id; const id_usuario = req.user.id;
return this.operationsService.chargePrint(data, id_usuario); 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') @Post('receipt')
async addCredit(@Body() data, @Req() req: any) { async addCredit(@Body() data, @Req() req: any) {
const id_usuario = req.user.id; const id_usuario = req.user.id;
return this.operationsService.addCredit(data, id_usuario); 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') @Post('registration')
async addReceiptInscription(@Body() data, @Req() req: any) { async addReceiptInscription(@Body() data, @Req() req: any) {
const id_usuario = req.user.id; const id_usuario = req.user.id;
return this.operationsService.addReceiptInscription(data, id_usuario); 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') @Post('time')
async addTime(@Body() data, @Req() req: any) { async addTime(@Body() data, @Req() req: any) {
const id_usuario = req.user.id; const id_usuario = req.user.id;
+10 -5
View File
@@ -11,31 +11,36 @@ import { Role } from 'src/role.enum';
export class AlumnoController { export class AlumnoController {
constructor(private readonly alumnoService: AlumnoService) { } constructor(private readonly alumnoService: AlumnoService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
async find() { async find() {
return this.alumnoService.findAll() return this.alumnoService.findAll()
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post() @Post()
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> { async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
return this.alumnoService.create(createStudentDto); 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') @Get(':id')
findOneWhitSancion(@Param('id') id: number) { findOneWhitSancion(@Param('id') id: number) {
return this.alumnoService.findOneWhitSancion(+id); 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') @Get('sancion/:id')
findOne(@Param('id') id: number) { findOne(@Param('id') id: number) {
return this.alumnoService.findOne(+id); return this.alumnoService.findOne(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('/create') @Post('/create')
async newStudent(@Body() createStudentDto: CreateStudentDto) { async newStudent(@Body() createStudentDto: CreateStudentDto) {
return this.alumnoService.create(createStudentDto); return this.alumnoService.create(createStudentDto);
@@ -5,36 +5,44 @@ import {
} from './dto/create-alumno_inscrito.dto'; } from './dto/create-alumno_inscrito.dto';
import { AlumnoInscrito } from './entities/alumno_inscrito.entity'; import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('alumno-inscrito')
export class AlumnoInscritoController { export class AlumnoInscritoController {
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { } constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Post() @Post()
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> { async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
return this.alumnoInscritoService.createWhitoutPay(dto); return this.alumnoInscritoService.createWhitoutPay(dto);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
async findAll(): Promise<AlumnoInscrito[]> { async findAll(): Promise<AlumnoInscrito[]> {
return this.alumnoInscritoService.findAll(); return this.alumnoInscritoService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get("/inscritos/:idPeriodo") @Get("/inscritos/:idPeriodo")
async findAllInscritos(@Param('idPeriodo') idPeriodo: number) { async findAllInscritos(@Param('idPeriodo') idPeriodo: number) {
return this.alumnoInscritoService.findAllInscritos(idPeriodo); return this.alumnoInscritoService.findAllInscritos(idPeriodo);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/plataforma') @Get('/plataforma')
async findAllPlataforma() { async findAllPlataforma() {
return this.alumnoInscritoService.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') @Get(':id_cuenta')
async findByIdWhitoud( async findByIdWhitoud(
@Param('id_cuenta') id_cuenta: number, @Param('id_cuenta') id_cuenta: number,
@@ -42,7 +50,8 @@ export class AlumnoInscritoController {
return this.alumnoInscritoService.findByIdWhitoud(id_cuenta); 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') @Get(':id_cuenta/sancion')
async findById( async findById(
@Param('id_cuenta') id_cuenta: number, @Param('id_cuenta') id_cuenta: number,
@@ -2,24 +2,30 @@ import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/c
import { AlumnoSancionService } from './alumno_sancion.service'; import { AlumnoSancionService } from './alumno_sancion.service';
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto'; import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('alumno-sancion')
export class AlumnoSancionController { export class AlumnoSancionController {
constructor(private readonly alumnoSancionService: AlumnoSancionService) { } constructor(private readonly alumnoSancionService: AlumnoSancionService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post() @Post()
async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) { async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) {
return this.alumnoSancionService.create(createAlumnoSancionDto); return this.alumnoSancionService.create(createAlumnoSancionDto);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findbyStudent(@Param('id') id: number) { findbyStudent(@Param('id') id: number) {
return this.alumnoSancionService.findbyStudent(+id); return this.alumnoSancionService.findbyStudent(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Delete(':id_cuenta') @Delete(':id_cuenta')
async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) { async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) {
return this.alumnoSancionService.removeByStudent(+id_cuenta); return this.alumnoSancionService.removeByStudent(+id_cuenta);
@@ -1,24 +1,30 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { AreaUbicacionService } from './area_ubicacion.service'; import { AreaUbicacionService } from './area_ubicacion.service';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('area-ubicacion')
export class AreaUbicacionController { export class AreaUbicacionController {
constructor(private readonly areaUbicacionService: AreaUbicacionService) { } constructor(private readonly areaUbicacionService: AreaUbicacionService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Get() @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get()
findAll() { findAll() {
return this.areaUbicacionService.findAll(); return this.areaUbicacionService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { findOne(@Param('id') id: string) {
return this.areaUbicacionService.findOne(+id); return this.areaUbicacionService.findOne(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/programs/:id') @Get('/programs/:id')
findProgramsByArea(@Param('id') id: number) { findProgramsByArea(@Param('id') id: number) {
return this.areaUbicacionService.findProgramsByArea(+id) return this.areaUbicacionService.findProgramsByArea(+id)
+17 -7
View File
@@ -2,30 +2,37 @@ import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/co
import { BitacoraService } from './bitacora.service'; import { BitacoraService } from './bitacora.service';
import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto'; import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('bitacora')
export class BitacoraController { export class BitacoraController {
constructor(private readonly bitacoraService: BitacoraService) { } constructor(private readonly bitacoraService: BitacoraService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Post() @Post()
assignment(@Body() createBitacoraDto: CreateBitacoraDto) { assignment(@Body() createBitacoraDto: CreateBitacoraDto) {
return this.bitacoraService.assignment(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') @Get('/cuenta/:id')
findOneByAcount(@Param('id') id: string) { findOneByAcount(@Param('id') id: string) {
return this.bitacoraService.findOneByAcount(+id); 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') @Get('/equipo/:id')
findOneByMachine(@Param('id') id: string) { findOneByMachine(@Param('id') id: string) {
return this.bitacoraService.findOneByMachine(+id); 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') @Patch('cancelar/:id')
cancelationByMachine( cancelationByMachine(
@Param('id') id: number, @Param('id') id: number,
@@ -34,13 +41,15 @@ export class BitacoraController {
return this.bitacoraService.cancelation(id, tiempo_asignado); return this.bitacoraService.cancelation(id, tiempo_asignado);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
findAll() { findAll() {
return this.bitacoraService.findAll(); return this.bitacoraService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('equipos-por-dia') @Post('equipos-por-dia')
async obtenerEquipos( async obtenerEquipos(
@Body() dto: BitacoraAlumnoDto @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') @Post('equipos-por-equipo')
async equiposPorEquipo( async equiposPorEquipo(
@Body() dto: EquiposPorEquipoDto, @Body() dto: EquiposPorEquipoDto,
+19 -8
View File
@@ -10,48 +10,58 @@ import {
import { BitacoraMesaService } from './bitacora_mesa.service'; import { BitacoraMesaService } from './bitacora_mesa.service';
import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto'; import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('bitacora-mesa')
export class BitacoraMesaController { export class BitacoraMesaController {
constructor(private readonly bitacoraMesaService: BitacoraMesaService) { } constructor(private readonly bitacoraMesaService: BitacoraMesaService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Post() @Post()
assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) { assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) {
return this.bitacoraMesaService.assignment(createBitacoraMesaDto); return this.bitacoraMesaService.assignment(createBitacoraMesaDto);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
findAll() { findAll() {
return this.bitacoraMesaService.findAll(); return this.bitacoraMesaService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { findOne(@Param('id') id: string) {
return this.bitacoraMesaService.findOne(+id); 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') @Get('/cuenta/:id_cuenta')
findByCuenta(@Param('id_cuenta') id_cuenta: string) { findByCuenta(@Param('id_cuenta') id_cuenta: string) {
return this.bitacoraMesaService.findByCuenta(+id_cuenta); 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') @Get('/table/:id_mesa')
findByTable(@Param('id_mesa') id_mesa: number) { findByTable(@Param('id_mesa') id_mesa: number) {
return this.bitacoraMesaService.findByTable(id_mesa); return this.bitacoraMesaService.findByTable(id_mesa);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('/date') @Post('/date')
findByDate(@Body() data: FindByDate) { findByDate(@Body() data: FindByDate) {
return this.bitacoraMesaService.findByDate(data.date); 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') @Patch('cancelar/:id')
cancelationByMachine( cancelationByMachine(
@Param('id') id: number, @Param('id') id: number,
@@ -60,7 +70,8 @@ export class BitacoraMesaController {
return this.bitacoraMesaService.cancelation(id, tiempo_asignado); return this.bitacoraMesaService.cancelation(id, tiempo_asignado);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('mesas-por-dia') @Post('mesas-por-dia')
mesasPorDia(@Body() body: { fecha: string }) { mesasPorDia(@Body() body: { fecha: string }) {
return this.bitacoraMesaService.mesasPorFecha(body.fecha); return this.bitacoraMesaService.mesasPorFecha(body.fecha);
+5 -1
View File
@@ -2,12 +2,16 @@ import { Controller, Get, UseGuards } from '@nestjs/common';
import { CarreraService } from './carrera.service'; import { CarreraService } from './carrera.service';
import { Carrera } from './entities/carrera.entity'; import { Carrera } from './entities/carrera.entity';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('carrera')
export class CarreraController { export class CarreraController {
constructor(private readonly carreraService: CarreraService) { } constructor(private readonly carreraService: CarreraService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get() @Get()
findAll(): Promise<Carrera[]> { findAll(): Promise<Carrera[]> {
return this.carreraService.findAll(); return this.carreraService.findAll();
+7 -2
View File
@@ -1,18 +1,23 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { CostoService } from './costo.service'; import { CostoService } from './costo.service';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('costo')
export class CostoController { export class CostoController {
constructor(private readonly costoService: CostoService) { } 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() @Get()
findAll() { findAll() {
return this.costoService.findAll(); return this.costoService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/:id_servicio') @Get('/:id_servicio')
find(@Param('id_servicio') id_servicio: number) { find(@Param('id_servicio') id_servicio: number) {
return this.costoService.find(id_servicio); return this.costoService.find(id_servicio);
@@ -2,19 +2,24 @@ import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { DetalleServicioService } from './detalle_servicio.service'; import { DetalleServicioService } from './detalle_servicio.service';
import { FindReciboByRangeDto } from 'src/recibo/dto/create-recibo.dto'; import { FindReciboByRangeDto } from 'src/recibo/dto/create-recibo.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('detalle-servicio')
export class DetalleServicioController { export class DetalleServicioController {
constructor(private readonly detalleServicioService: DetalleServicioService) { } constructor(private readonly detalleServicioService: DetalleServicioService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
findAll() { findAll() {
return this.detalleServicioService.findAll() return this.detalleServicioService.findAll()
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('rango') @Post('rango')
async findByDateRange(@Body() data: FindReciboByRangeDto) { async findByDateRange(@Body() data: FindReciboByRangeDto) {
return this.detalleServicioService.findByDateRange(data.desde, data.hasta); return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
+23 -10
View File
@@ -3,66 +3,79 @@ import { EquipoService } from './equipo.service';
import { Equipo } from './entities/equipo.entity'; import { Equipo } from './entities/equipo.entity';
import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto'; import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('equipo')
export class EquipoController { export class EquipoController {
constructor(private readonly equipoService: EquipoService) { } constructor(private readonly equipoService: EquipoService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Get() @Get()
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
findAll(): Promise<Equipo[]> { findAll(): Promise<Equipo[]> {
return this.equipoService.findAll(); return this.equipoService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get('/active') @Get('/active')
findActive() { findActive() {
return this.equipoService.findActive(); return this.equipoService.findActive();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/disable') @Get('/disable')
findDisable() { findDisable() {
return this.equipoService.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') @Get('/student/:id')
findOnlyUsable(@Param('id') id: number): Promise<Equipo[]> { findOnlyUsable(@Param('id') id: number): Promise<Equipo[]> {
return this.equipoService.findOnlyUsable(+id); return this.equipoService.findOnlyUsable(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/busy') @Get('/busy')
findOnlyBusy(): Promise<Equipo[]> { findOnlyBusy(): Promise<Equipo[]> {
return this.equipoService.findOnlyBusy(); return this.equipoService.findOnlyBusy();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string): Promise<Equipo> { findOne(@Param('id') id: string): Promise<Equipo> {
return this.equipoService.findOne(id); return this.equipoService.findOne(id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post() @Post()
create(@Body() equipo: CreateEquipoDto) { create(@Body() equipo: CreateEquipoDto) {
return this.equipoService.create(equipo); return this.equipoService.create(equipo);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch() @Patch()
update(@Body() equipo: CreateEquipoDto) { update(@Body() equipo: CreateEquipoDto) {
return this.equipoService.update(equipo); 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') @Patch(':id/activo')
toggleActivo(@Param('id') id: number) { toggleActivo(@Param('id') id: number) {
return this.equipoService.toggleActivo(+id); 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') @Patch('actualizar-area')
actualizarPorArea( actualizarPorArea(
@Body() updateAreaEquiposDto: UpdateAreaEquiposDto, @Body() updateAreaEquiposDto: UpdateAreaEquiposDto,
+7 -3
View File
@@ -1,18 +1,22 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { MensajeService } from './mensaje.service'; import { MensajeService } from './mensaje.service';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('mensaje')
export class MensajeController { export class MensajeController {
constructor(private readonly mensajeService: MensajeService) { } constructor(private readonly mensajeService: MensajeService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Get() @Get() @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
findAll() { findAll() {
return this.mensajeService.findAll(); return this.mensajeService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { findOne(@Param('id') id: string) {
return this.mensajeService.findOne(+id); return this.mensajeService.findOne(+id);
+13 -5
View File
@@ -2,30 +2,37 @@ import { Controller, Body, Patch, Param, Get, UseGuards } from '@nestjs/common';
import { MesaService } from './mesa.service'; import { MesaService } from './mesa.service';
import { UpdateMesaDto } from './dto/update-mesa.dto'; import { UpdateMesaDto } from './dto/update-mesa.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('mesa')
export class MesaController { export class MesaController {
constructor(private readonly mesaService: MesaService) { } constructor(private readonly mesaService: MesaService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get() @Get()
async findAll() { async findAll() {
return this.mesaService.findAll(); return this.mesaService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get('activo') @Get('activo')
async findAllActivo() { async findAllActivo() {
return this.mesaService.findAllActivo(); return this.mesaService.findAllActivo();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
@Get('uso') @Get('uso')
async findActiveMesas() { async findActiveMesas() {
return this.mesaService.findActiveMesas(); return this.mesaService.findActiveMesas();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch(':id') @Patch(':id')
async updateActivo( async updateActivo(
@Param('id') id: number, @Param('id') id: number,
@@ -34,7 +41,8 @@ export class MesaController {
return this.mesaService.updateActivo(id, updateMesaDto); 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') @Patch(':id/activo')
toggleActivo(@Param('id') id: number) { toggleActivo(@Param('id') id: number) {
return this.mesaService.toggleActivo(+id); return this.mesaService.toggleActivo(+id);
+11 -1
View File
@@ -2,27 +2,37 @@ import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } fro
import { PeriodoService } from './periodo.service'; import { PeriodoService } from './periodo.service';
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto'; import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('periodo')
export class PeriodoController { export class PeriodoController {
constructor(private readonly periodoService: PeriodoService) { } constructor(private readonly periodoService: PeriodoService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
findAll() { findAll() {
return this.periodoService.findAll(); return this.periodoService.findAll();
} }
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post() @Post()
create(@Body() data: CreatePeriodoDto) { create(@Body() data: CreatePeriodoDto) {
return this.periodoService.create(data); return this.periodoService.create(data);
} }
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Delete("/:id_periodo") @Delete("/:id_periodo")
delete(@Param("id_periodo") id_periodo: number) { delete(@Param("id_periodo") id_periodo: number) {
return this.periodoService.delete(id_periodo) return this.periodoService.delete(id_periodo)
} }
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch("/date/:id_periodo") @Patch("/date/:id_periodo")
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) { modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
return this.periodoService.modifiedDate(data, id_periodo) return this.periodoService.modifiedDate(data, id_periodo)
+13 -5
View File
@@ -2,36 +2,44 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@n
import { ProgramaService } from './programa.service'; import { ProgramaService } from './programa.service';
import { UpdateProgramaDto } from './dto/update-programa.dto'; import { UpdateProgramaDto } from './dto/update-programa.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('programa')
export class ProgramaController { export class ProgramaController {
constructor(private readonly programaService: ProgramaService) { } constructor(private readonly programaService: ProgramaService) { }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get() @Get()
findAll() { findAll() {
return this.programaService.findAll(); return this.programaService.findAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { findOne(@Param('id') id: string) {
return this.programaService.findOne(+id); return this.programaService.findOne(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post() @Post()
create(@Body() body) { create(@Body() body) {
return this.programaService.create(body); return this.programaService.create(body);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch(':id') @Patch(':id')
update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) { update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) {
return this.programaService.update(+id, updateProgramaDto); return this.programaService.update(+id, updateProgramaDto);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Delete(':id') @Delete(':id')
delete(@Param('id') id:string){ delete(@Param('id') id:string){
return this.programaService.delete(+id); return this.programaService.delete(+id);
@@ -2,30 +2,38 @@ import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common';
import { ProgramaEquipoService } from './programa_equipo.service'; import { ProgramaEquipoService } from './programa_equipo.service';
import { UpdateProgramaEquipoDto, UpdateProgramasSalaDto } from './dto/update-programa_equipo.dto'; import { UpdateProgramaEquipoDto, UpdateProgramasSalaDto } from './dto/update-programa_equipo.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('programa-equipo')
export class ProgramaEquipoController { 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') @Get('programas/:id')
findAllProgramByNumber(@Param('id') id: number) { findAllProgramByNumber(@Param('id') id: number) {
return this.programaEquipoService.findAllProgramByNumber(+id); return this.programaEquipoService.findAllProgramByNumber(+id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('ubicacion/:id') @Get('ubicacion/:id')
findAllProgramByUbicacion(@Param('id') id: string) { findAllProgramByUbicacion(@Param('id') id: string) {
return this.programaEquipoService.findAllProgramByUbication(id); return this.programaEquipoService.findAllProgramByUbication(id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { findOne(@Param('id') id: string) {
return this.programaEquipoService.findOne(id); return this.programaEquipoService.findOne(id);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch('equipo/:id') @Patch('equipo/:id')
updateMachine( updateMachine(
@Param('id') id: string, @Param('id') id: string,
@@ -37,7 +45,8 @@ export class ProgramaEquipoController {
); );
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Patch('sala') @Patch('sala')
updateBySala(@Body() dto: UpdateProgramasSalaDto) { updateBySala(@Body() dto: UpdateProgramasSalaDto) {
return this.programaEquipoService.updateBySala(dto.sala, dto.programas); return this.programaEquipoService.updateBySala(dto.sala, dto.programas);
+6 -3
View File
@@ -3,17 +3,20 @@ import {
Post, Post,
Body, Body,
UseGuards, UseGuards,
Req,
} from '@nestjs/common'; } from '@nestjs/common';
import { ReciboService } from './recibo.service'; import { ReciboService } from './recibo.service';
import { FindReciboByRangeDto } from './dto/create-recibo.dto'; import { FindReciboByRangeDto } from './dto/create-recibo.dto';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('recibo')
export class ReciboController { 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') @Post('rango')
async findByDateRange(@Body() data: FindReciboByRangeDto) { async findByDateRange(@Body() data: FindReciboByRangeDto) {
return this.reciboService.findByDateRange(data.desde, data.hasta); return this.reciboService.findByDateRange(data.desde, data.hasta);
+6 -4
View File
@@ -1,5 +1,7 @@
export enum Role { export enum Role {
ADMINISTRADOR = 'ADMINISTRADOR', ADMINISTRADOR = 1,
OPERADOR = 'OPERADOR', ATENCION_USUARIOS = 2,
} SERVICIO_SOCIAL = 3,
SUPER_ADMINISTRADOR = 4,
PCPUMA = 5,
}
+2 -2
View File
@@ -6,7 +6,7 @@ import { ROLES_KEY } from './roles.decorator';
@Injectable() @Injectable()
export class RolesGuard implements CanActivate { export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {} constructor(private reflector: Reflector) { }
canActivate(context: ExecutionContext): boolean { canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [ const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
@@ -17,6 +17,6 @@ export class RolesGuard implements CanActivate {
return true; return true;
} }
const { user } = context.switchToHttp().getRequest(); const { user } = context.switchToHttp().getRequest();
return requiredRoles.some((role) => user.role?.includes(role)); return requiredRoles.some((role) => user.role === role);
} }
} }
+8 -3
View File
@@ -1,17 +1,22 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { SancionService } from './sancion.service'; import { SancionService } from './sancion.service';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('sancion')
export class SancionController { 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() @Get()
find() { find() {
return this.sancionService.find(); return this.sancionService.find();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get(':id') @Get(':id')
findOne(@Param('id') id: number) { findOne(@Param('id') id: number) {
return this.sancionService.findOne(+id); return this.sancionService.findOne(+id);
+6 -2
View File
@@ -1,12 +1,16 @@
import { Controller, Get, UseGuards } from '@nestjs/common'; import { Controller, Get, UseGuards } from '@nestjs/common';
import { ServicioService } from './servicio.service'; import { ServicioService } from './servicio.service';
import { JwtAuthGuard } from 'src/user/jwt.guard'; 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') @Controller('servicio')
export class ServicioController { 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() @Get()
findAll() { findAll() {
return this.servicioService.findAll(); return this.servicioService.findAll();
+12 -5
View File
@@ -11,18 +11,23 @@ import type { Response } from 'express';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto'; import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
import { JwtAuthGuard } from './jwt.guard'; 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') @Controller('user')
export class UserController { 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() @Get()
async getAll() { async getAll() {
return this.userService.getAll(); return this.userService.getAll();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Get('/perfil') @Get('/perfil')
async getAllPerfil() { async getAllPerfil() {
return this.userService.getAllPerfil(); return this.userService.getAllPerfil();
@@ -39,13 +44,15 @@ export class UserController {
return req.user.role; return req.user.role;
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('/create') @Post('/create')
async createUser(@Body() data: CreateUserDto) { async createUser(@Body() data: CreateUserDto) {
return this.userService.create(data); return this.userService.create(data);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
@Post('/changePassword') @Post('/changePassword')
async changePassword(@Body() data: changePasswordDto, @Req() req) { async changePassword(@Body() data: changePasswordDto, @Req() req) {
const id_usuario = req.user.id; const id_usuario = req.user.id;