From 472bfebb7a215245263f0fda3f614a96aa66d637 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 23 Feb 2026 18:05:09 -0600 Subject: [PATCH 1/6] fixed ep mesa --- src/alumno/student.controller.ts | 4 ++-- src/mesa/mesa.service.ts | 35 ++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/alumno/student.controller.ts b/src/alumno/student.controller.ts index 3db9341..d0354be 100644 --- a/src/alumno/student.controller.ts +++ b/src/alumno/student.controller.ts @@ -21,13 +21,13 @@ export class AlumnoController { return this.alumnoService.create(createStudentDto); } - //@UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard) @Get(':id') findOneWhitSancion(@Param('id') id: number) { return this.alumnoService.findOneWhitSancion(+id); } - //@UseGuards(JwtAuthGuard) + @UseGuards(JwtAuthGuard) @Get('sancion/:id') findOne(@Param('id') id: number) { return this.alumnoService.findOne(+id); diff --git a/src/mesa/mesa.service.ts b/src/mesa/mesa.service.ts index c089e2b..03b63b7 100644 --- a/src/mesa/mesa.service.ts +++ b/src/mesa/mesa.service.ts @@ -38,15 +38,42 @@ export class MesaService { }); } - - async findAll(): Promise { return await this.mesaRepository.find(); } - async findAllActivo(): Promise { - return await this.mesaRepository.find({ where: { activo: true } }); + const mesas = await this.mesaRepository + .createQueryBuilder('mesa') + + .andWhere('mesa.activo = true') + + .andWhere((qb) => { + const subQuery = qb + .subQuery() + .select('bitacora_mesa.id_mesa') + .from('bitacora_mesa', 'bitacora_mesa') + .where( + `TIMESTAMPDIFF( + SECOND, + NOW(), + DATE_ADD(bitacora_mesa.tiempo_entrada, INTERVAL bitacora_mesa.tiempo_asignado MINUTE) + ) > 0`, + ) + .getQuery(); + + return `mesa.id_mesa NOT IN ${subQuery}`; + }) + + .orderBy('mesa.id_mesa', 'ASC') + + .getMany(); + + if (!mesas.length) { + throw new NotFoundException('No usable table found'); + } + + return mesas; } async updateActivo(id: number, updateMesaDto: UpdateMesaDto) { From 18b869d681308775e728f199156c84e1667a5948 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 23 Feb 2026 18:16:17 -0600 Subject: [PATCH 2/6] added guard jwt --- src/alumno/student.controller.ts | 3 ++ .../alumno_inscrito.controller.ts | 33 +++++-------------- .../alumno_sancion.controller.ts | 8 +++-- .../area_ubicacion.controller.ts | 10 ++++-- src/bitacora/bitacora.controller.ts | 11 +++++-- src/bitacora_mesa/bitacora_mesa.controller.ts | 11 ++++++- src/carrera/carrera.controller.ts | 6 ++-- src/costo/costo.controller.ts | 4 ++- .../detalle_servicio.controller.ts | 9 +++-- src/equipo/equipo.controller.ts | 13 +++++++- src/mensaje/mensaje.controller.ts | 9 ++--- src/mesa/mesa.controller.ts | 7 +++- src/periodo/periodo.controller.ts | 8 +++-- src/programa/programa.controller.ts | 8 ++++- .../programa_equipo.controller.ts | 8 ++++- src/recibo/recibo.controller.ts | 2 ++ src/sancion/sancion.controller.ts | 5 ++- src/servicio/servicio.controller.ts | 5 ++- src/user/user.controller.ts | 5 ++- 19 files changed, 112 insertions(+), 53 deletions(-) diff --git a/src/alumno/student.controller.ts b/src/alumno/student.controller.ts index d0354be..ac77915 100644 --- a/src/alumno/student.controller.ts +++ b/src/alumno/student.controller.ts @@ -11,11 +11,13 @@ import { Role } from 'src/role.enum'; export class AlumnoController { constructor(private readonly alumnoService: AlumnoService) { } + @UseGuards(JwtAuthGuard) @Get() async find() { return this.alumnoService.findAll() } + @UseGuards(JwtAuthGuard) @Post() async create(@Body() createStudentDto: CreateStudentDto): Promise { return this.alumnoService.create(createStudentDto); @@ -33,6 +35,7 @@ export class AlumnoController { return this.alumnoService.findOne(+id); } + @UseGuards(JwtAuthGuard) @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 5e2aa7b..831ff31 100644 --- a/src/alumno_inscrito/alumno_inscrito.controller.ts +++ b/src/alumno_inscrito/alumno_inscrito.controller.ts @@ -1,44 +1,40 @@ -import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common'; +import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/common'; import { AlumnoInscritoService } from './alumno_inscrito.service'; import { CreateAlumnoInscritoDto, } from './dto/create-alumno_inscrito.dto'; import { AlumnoInscrito } from './entities/alumno_inscrito.entity'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('alumno-inscrito') export class AlumnoInscritoController { constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { } + @UseGuards(JwtAuthGuard) @Post() async create(@Body() dto: CreateAlumnoInscritoDto): Promise { return this.alumnoInscritoService.createWhitoutPay(dto); } + @UseGuards(JwtAuthGuard) @Get() async findAll(): Promise { return this.alumnoInscritoService.findAll(); } + @UseGuards(JwtAuthGuard) @Get("/inscritos/:idPeriodo") async findAllInscritos(@Param('idPeriodo') idPeriodo: number) { return this.alumnoInscritoService.findAllInscritos(idPeriodo); } - // @Post('/tiempo') - // async addTime(@Body() body: AddTimeDto) { - // const { idCuenta, idPlataforma, tiempoExtra } = body; - // return this.alumnoInscritoService.( - // idCuenta, - // idPlataforma, - // tiempoExtra, - // ); - // } - + @UseGuards(JwtAuthGuard) @Get('/plataforma') async findAllPlataforma() { return this.alumnoInscritoService.findAllPlataforma(); } + @UseGuards(JwtAuthGuard) @Get(':id_cuenta') async findByIdWhitoud( @Param('id_cuenta') id_cuenta: number, @@ -46,24 +42,11 @@ export class AlumnoInscritoController { return this.alumnoInscritoService.findByIdWhitoud(id_cuenta); } + @UseGuards(JwtAuthGuard) @Get(':id_cuenta/sancion') async findById( @Param('id_cuenta') id_cuenta: number, ): Promise { return this.alumnoInscritoService.findById(id_cuenta); } - - //pruebas borrar - @Patch('platica/:idCuenta/:idPeriodo/:idPlataforma') - marcarPlatica( - @Param('idCuenta') idCuenta: number, - @Param('idPeriodo') idPeriodo: number, - @Param('idPlataforma') idPlataforma: number, - ) { - return this.alumnoInscritoService.marcarPlatica( - idCuenta, - idPeriodo, - idPlataforma, - ); - } } diff --git a/src/alumno_sancion/alumno_sancion.controller.ts b/src/alumno_sancion/alumno_sancion.controller.ts index 902ba38..6aabdbd 100644 --- a/src/alumno_sancion/alumno_sancion.controller.ts +++ b/src/alumno_sancion/alumno_sancion.controller.ts @@ -1,21 +1,25 @@ -import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common'; import { AlumnoSancionService } from './alumno_sancion.service'; import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('alumno-sancion') export class AlumnoSancionController { - constructor(private readonly alumnoSancionService: AlumnoSancionService) {} + constructor(private readonly alumnoSancionService: AlumnoSancionService) { } + @UseGuards(JwtAuthGuard) @Post() async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) { return this.alumnoSancionService.create(createAlumnoSancionDto); } + @UseGuards(JwtAuthGuard) @Get(':id') findbyStudent(@Param('id') id: number) { return this.alumnoSancionService.findbyStudent(+id); } + @UseGuards(JwtAuthGuard) @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 6c8a6c2..18615e2 100644 --- a/src/area_ubicacion/area_ubicacion.controller.ts +++ b/src/area_ubicacion/area_ubicacion.controller.ts @@ -1,22 +1,26 @@ -import { Controller, Get, Param } from '@nestjs/common'; +import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { AreaUbicacionService } from './area_ubicacion.service'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('area-ubicacion') export class AreaUbicacionController { - constructor(private readonly areaUbicacionService: AreaUbicacionService) {} + constructor(private readonly areaUbicacionService: AreaUbicacionService) { } + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.areaUbicacionService.findAll(); } + @UseGuards(JwtAuthGuard) @Get(':id') findOne(@Param('id') id: string) { return this.areaUbicacionService.findOne(+id); } + @UseGuards(JwtAuthGuard) @Get('/programs/:id') - findProgramsByArea(@Param('id')id:number){ + 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 709597a..593c68e 100644 --- a/src/bitacora/bitacora.controller.ts +++ b/src/bitacora/bitacora.controller.ts @@ -1,26 +1,31 @@ -import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common'; +import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/common'; import { BitacoraService } from './bitacora.service'; import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('bitacora') export class BitacoraController { constructor(private readonly bitacoraService: BitacoraService) { } + @UseGuards(JwtAuthGuard) @Post() assignment(@Body() createBitacoraDto: CreateBitacoraDto) { return this.bitacoraService.assignment(createBitacoraDto); } + @UseGuards(JwtAuthGuard) @Get('/cuenta/:id') findOneByAcount(@Param('id') id: string) { return this.bitacoraService.findOneByAcount(+id); } + @UseGuards(JwtAuthGuard) @Get('/equipo/:id') findOneByMachine(@Param('id') id: string) { return this.bitacoraService.findOneByMachine(+id); } + @UseGuards(JwtAuthGuard) @Patch('cancelar/:id') cancelationByMachine( @Param('id') id: number, @@ -29,12 +34,13 @@ export class BitacoraController { return this.bitacoraService.cancelation(id, tiempo_asignado); } + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.bitacoraService.findAll(); } - + @UseGuards(JwtAuthGuard) @Post('equipos-por-dia') async obtenerEquipos( @Body() dto: BitacoraAlumnoDto @@ -45,6 +51,7 @@ export class BitacoraController { ); } + @UseGuards(JwtAuthGuard) @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 ab2bc59..b5e3525 100644 --- a/src/bitacora_mesa/bitacora_mesa.controller.ts +++ b/src/bitacora_mesa/bitacora_mesa.controller.ts @@ -5,45 +5,53 @@ import { Body, Patch, Param, - Delete, + UseGuards, } from '@nestjs/common'; import { BitacoraMesaService } from './bitacora_mesa.service'; import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('bitacora-mesa') export class BitacoraMesaController { constructor(private readonly bitacoraMesaService: BitacoraMesaService) { } + @UseGuards(JwtAuthGuard) @Post() assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) { return this.bitacoraMesaService.assignment(createBitacoraMesaDto); } + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.bitacoraMesaService.findAll(); } + @UseGuards(JwtAuthGuard) @Get(':id') findOne(@Param('id') id: string) { return this.bitacoraMesaService.findOne(+id); } + @UseGuards(JwtAuthGuard) @Get('/cuenta/:id_cuenta') findByCuenta(@Param('id_cuenta') id_cuenta: string) { return this.bitacoraMesaService.findByCuenta(+id_cuenta); } + @UseGuards(JwtAuthGuard) @Get('/table/:id_mesa') findByTable(@Param('id_mesa') id_mesa: number) { return this.bitacoraMesaService.findByTable(id_mesa); } + @UseGuards(JwtAuthGuard) @Post('/date') findByDate(@Body() data: FindByDate) { return this.bitacoraMesaService.findByDate(data.date); } + @UseGuards(JwtAuthGuard) @Patch('cancelar/:id') cancelationByMachine( @Param('id') id: number, @@ -52,6 +60,7 @@ export class BitacoraMesaController { return this.bitacoraMesaService.cancelation(id, tiempo_asignado); } + @UseGuards(JwtAuthGuard) @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 a93b349..4ab0e94 100644 --- a/src/carrera/carrera.controller.ts +++ b/src/carrera/carrera.controller.ts @@ -1,11 +1,13 @@ -import { Controller, Get } from '@nestjs/common'; +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'; @Controller('carrera') export class CarreraController { - constructor(private readonly carreraService: CarreraService) {} + constructor(private readonly carreraService: CarreraService) { } + @UseGuards(JwtAuthGuard) @Get() findAll(): Promise { return this.carreraService.findAll(); diff --git a/src/costo/costo.controller.ts b/src/costo/costo.controller.ts index aa253bc..59883e8 100644 --- a/src/costo/costo.controller.ts +++ b/src/costo/costo.controller.ts @@ -1,10 +1,12 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; import { CostoService } from './costo.service'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('costo') export class CostoController { constructor(private readonly costoService: CostoService) {} + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.costoService.findAll(); diff --git a/src/detalle_servicio/detalle_servicio.controller.ts b/src/detalle_servicio/detalle_servicio.controller.ts index 6c268c4..9158501 100644 --- a/src/detalle_servicio/detalle_servicio.controller.ts +++ b/src/detalle_servicio/detalle_servicio.controller.ts @@ -1,17 +1,20 @@ -import { Body, Controller, Get, Post } from '@nestjs/common'; +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'; @Controller('detalle-servicio') export class DetalleServicioController { - constructor(private readonly detalleServicioService: DetalleServicioService) {} + constructor(private readonly detalleServicioService: DetalleServicioService) { } + @UseGuards(JwtAuthGuard) @Get() - findAll(){ + findAll() { return this.detalleServicioService.findAll() } + @UseGuards(JwtAuthGuard) @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 febf7f0..1d712e8 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -1,57 +1,68 @@ -import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; +import { Body, Controller, Get, Param, Patch, Post, UseGuards } from '@nestjs/common'; 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'; @Controller('equipo') export class EquipoController { constructor(private readonly equipoService: EquipoService) { } + @UseGuards(JwtAuthGuard) @Get() findAll(): Promise { return this.equipoService.findAll(); } + @UseGuards(JwtAuthGuard) @Get('/active') findActive() { return this.equipoService.findActive(); } + @UseGuards(JwtAuthGuard) @Get('/disable') findDisable() { return this.equipoService.findDisable(); } + @UseGuards(JwtAuthGuard) @Get('/student/:id') findOnlyUsable(@Param('id') id: number): Promise { return this.equipoService.findOnlyUsable(+id); } + @UseGuards(JwtAuthGuard) @Get('/busy') findOnlyBusy(): Promise { return this.equipoService.findOnlyBusy(); } + @UseGuards(JwtAuthGuard) @Get(':id') findOne(@Param('id') id: string): Promise { return this.equipoService.findOne(id); } + @UseGuards(JwtAuthGuard) @Post() create(@Body() equipo: CreateEquipoDto) { return this.equipoService.create(equipo); } + @UseGuards(JwtAuthGuard) @Patch() update(@Body() equipo: CreateEquipoDto) { return this.equipoService.update(equipo); } + @UseGuards(JwtAuthGuard) @Patch(':id/activo') toggleActivo(@Param('id') id: number) { return this.equipoService.toggleActivo(+id); } + @UseGuards(JwtAuthGuard) @Patch('actualizar-area') actualizarPorArea( @Body() updateAreaEquiposDto: UpdateAreaEquiposDto, diff --git a/src/mensaje/mensaje.controller.ts b/src/mensaje/mensaje.controller.ts index ee8051e..a74d627 100644 --- a/src/mensaje/mensaje.controller.ts +++ b/src/mensaje/mensaje.controller.ts @@ -1,17 +1,18 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { MensajeService } from './mensaje.service'; -import { CreateMensajeDto } from './dto/create-mensaje.dto'; -import { UpdateMensajeDto } from './dto/update-mensaje.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('mensaje') export class MensajeController { - constructor(private readonly mensajeService: MensajeService) {} + constructor(private readonly mensajeService: MensajeService) { } + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.mensajeService.findAll(); } + @UseGuards(JwtAuthGuard) @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 e048d98..8ba9638 100644 --- a/src/mesa/mesa.controller.ts +++ b/src/mesa/mesa.controller.ts @@ -1,21 +1,25 @@ -import { Controller, Body, Patch, Param, Get } from '@nestjs/common'; +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'; @Controller('mesa') export class MesaController { constructor(private readonly mesaService: MesaService) { } + @UseGuards(JwtAuthGuard) @Get() async findAll() { return this.mesaService.findAll(); } + @UseGuards(JwtAuthGuard) @Get('activo') async findAllActivo() { return this.mesaService.findAllActivo(); } + @UseGuards(JwtAuthGuard) @Patch(':id') async updateActivo( @Param('id') id: number, @@ -24,6 +28,7 @@ export class MesaController { return this.mesaService.updateActivo(id, updateMesaDto); } + @UseGuards(JwtAuthGuard) @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 ddd1207..f68f5ac 100644 --- a/src/periodo/periodo.controller.ts +++ b/src/periodo/periodo.controller.ts @@ -1,12 +1,14 @@ -import { Controller, Get } from '@nestjs/common'; +import { Controller, Get, UseGuards } from '@nestjs/common'; import { PeriodoService } from './periodo.service'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('periodo') export class PeriodoController { - constructor(private readonly periodoService:PeriodoService){} + constructor(private readonly periodoService: PeriodoService) { } + @UseGuards(JwtAuthGuard) @Get() - findAll(){ + findAll() { return this.periodoService.findAll(); } } diff --git a/src/programa/programa.controller.ts b/src/programa/programa.controller.ts index 9041bac..755afbf 100644 --- a/src/programa/programa.controller.ts +++ b/src/programa/programa.controller.ts @@ -1,31 +1,37 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; import { ProgramaService } from './programa.service'; import { UpdateProgramaDto } from './dto/update-programa.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('programa') export class ProgramaController { constructor(private readonly programaService: ProgramaService) { } + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.programaService.findAll(); } + @UseGuards(JwtAuthGuard) @Get(':id') findOne(@Param('id') id: string) { return this.programaService.findOne(+id); } + @UseGuards(JwtAuthGuard) @Post() create(@Body() body) { return this.programaService.create(body); } + @UseGuards(JwtAuthGuard) @Patch(':id') update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) { return this.programaService.update(+id, updateProgramaDto); } + @UseGuards(JwtAuthGuard) @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 c8495b1..c32fd8f 100644 --- a/src/programa_equipo/programa_equipo.controller.ts +++ b/src/programa_equipo/programa_equipo.controller.ts @@ -1,26 +1,31 @@ -import { Controller, Get, Body, Patch, Param } from '@nestjs/common'; +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'; @Controller('programa-equipo') export class ProgramaEquipoController { constructor(private readonly programaEquipoService: ProgramaEquipoService) {} + @UseGuards(JwtAuthGuard) @Get('programas/:id') findAllProgramByNumber(@Param('id') id: number) { return this.programaEquipoService.findAllProgramByNumber(+id); } + @UseGuards(JwtAuthGuard) @Get('ubicacion/:id') findAllProgramByUbicacion(@Param('id') id: string) { return this.programaEquipoService.findAllProgramByUbication(id); } + @UseGuards(JwtAuthGuard) @Get(':id') findOne(@Param('id') id: string) { return this.programaEquipoService.findOne(id); } + @UseGuards(JwtAuthGuard) @Patch('equipo/:id') updateMachine( @Param('id') id: string, @@ -32,6 +37,7 @@ export class ProgramaEquipoController { ); } + @UseGuards(JwtAuthGuard) @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 2185030..74f3969 100644 --- a/src/recibo/recibo.controller.ts +++ b/src/recibo/recibo.controller.ts @@ -7,11 +7,13 @@ import { } from '@nestjs/common'; import { ReciboService } from './recibo.service'; import { FindReciboByRangeDto } from './dto/create-recibo.dto'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('recibo') export class ReciboController { constructor(private readonly reciboService: ReciboService) {} + @UseGuards(JwtAuthGuard) @Post('rango') async findByDateRange(@Body() data: FindReciboByRangeDto) { return this.reciboService.findByDateRange(data.desde, data.hasta); diff --git a/src/sancion/sancion.controller.ts b/src/sancion/sancion.controller.ts index 201ad08..c123b82 100644 --- a/src/sancion/sancion.controller.ts +++ b/src/sancion/sancion.controller.ts @@ -1,14 +1,17 @@ -import { Controller, Get, Param } from '@nestjs/common'; +import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { SancionService } from './sancion.service'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('sancion') export class SancionController { constructor(private readonly sancionService: SancionService) {} + @UseGuards(JwtAuthGuard) @Get() find() { return this.sancionService.find(); } + @UseGuards(JwtAuthGuard) @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 9333f70..2a44f26 100644 --- a/src/servicio/servicio.controller.ts +++ b/src/servicio/servicio.controller.ts @@ -1,9 +1,12 @@ -import { Controller, Get } from '@nestjs/common'; +import { Controller, Get, UseGuards } from '@nestjs/common'; import { ServicioService } from './servicio.service'; +import { JwtAuthGuard } from 'src/user/jwt.guard'; @Controller('servicio') export class ServicioController { constructor(private readonly servicioService: ServicioService) {} + + @UseGuards(JwtAuthGuard) @Get() findAll() { return this.servicioService.findAll(); diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index d420d6f..c4facd9 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -4,7 +4,6 @@ import { Post, Body, UseGuards, - Request, Res, Req, } from '@nestjs/common'; @@ -17,16 +16,19 @@ import { JwtAuthGuard } from './jwt.guard'; export class UserController { constructor(private readonly userService: UserService) {} + @UseGuards(JwtAuthGuard) @Get() async getAll() { return this.userService.getAll(); } + @UseGuards(JwtAuthGuard) @Get('/perfil') async getAllPerfil() { return this.userService.getAllPerfil(); } + @UseGuards(JwtAuthGuard) @Post() async Login(@Body() data: Login, @Res() res: Response) { return this.userService.Login(data, res); @@ -38,6 +40,7 @@ export class UserController { return req.user.role; } + @UseGuards(JwtAuthGuard) @Post('/create') async createUser(@Body() data: CreateUserDto) { return this.userService.create(data); From 9e836fb947cb5ae19e8b08db320418e7490ff5f0 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Fri, 27 Feb 2026 10:56:57 -0600 Subject: [PATCH 3/6] delete sommeting that not used --- src/costo/costo.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/costo/costo.controller.ts b/src/costo/costo.controller.ts index 79ef6fd..4f1a699 100644 --- a/src/costo/costo.controller.ts +++ b/src/costo/costo.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; +import { Controller, Get, Param, UseGuards } from '@nestjs/common'; import { CostoService } from './costo.service'; import { JwtAuthGuard } from 'src/user/jwt.guard'; From 8aa0eab353cf573c85bcc0dd4ce38c13bafd94ba Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 2 Mar 2026 12:05:08 -0600 Subject: [PATCH 4/6] delete error about sancion --- src/alumno_sancion/alumno_sancion.service.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/alumno_sancion/alumno_sancion.service.ts b/src/alumno_sancion/alumno_sancion.service.ts index b7f2cd1..78e46c8 100644 --- a/src/alumno_sancion/alumno_sancion.service.ts +++ b/src/alumno_sancion/alumno_sancion.service.ts @@ -56,9 +56,6 @@ export class AlumnoSancionService { where: { alumno: { id_cuenta } }, }); - if (alusancion.length === 0) { - throw new NotFoundException(`El estudiante no cuenta con una sanción activa`); - } return { student, alusancion }; } From 0323c93ca38d69857cc0195dec034286537e5c1f Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 2 Mar 2026 14:49:15 -0600 Subject: [PATCH 5/6] added all roles --- src/Operations/operations.controller.ts | 17 +++++++--- src/alumno/student.controller.ts | 15 ++++++--- .../alumno_inscrito.controller.ts | 21 ++++++++---- .../alumno_sancion.controller.ts | 12 +++++-- .../area_ubicacion.controller.ts | 14 +++++--- src/bitacora/bitacora.controller.ts | 24 ++++++++++---- src/bitacora_mesa/bitacora_mesa.controller.ts | 27 ++++++++++----- src/carrera/carrera.controller.ts | 6 +++- src/costo/costo.controller.ts | 9 +++-- .../detalle_servicio.controller.ts | 9 +++-- src/equipo/equipo.controller.ts | 33 +++++++++++++------ src/mensaje/mensaje.controller.ts | 10 ++++-- src/mesa/mesa.controller.ts | 18 +++++++--- src/periodo/periodo.controller.ts | 12 ++++++- src/programa/programa.controller.ts | 18 +++++++--- .../programa_equipo.controller.ts | 21 ++++++++---- src/recibo/recibo.controller.ts | 9 +++-- src/role.enum.ts | 10 +++--- src/roles.guard.ts | 4 +-- src/sancion/sancion.controller.ts | 11 +++++-- src/servicio/servicio.controller.ts | 8 +++-- src/user/user.controller.ts | 17 +++++++--- 22 files changed, 233 insertions(+), 92 deletions(-) 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; From 53ab8c5c273b094be3137f695700eab8b0ce4de1 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 2 Mar 2026 18:38:42 -0600 Subject: [PATCH 6/6] modified get periodo and return user --- src/periodo/periodo.service.ts | 12 ++++++------ src/user/user.service.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/periodo/periodo.service.ts b/src/periodo/periodo.service.ts index 2f9ac30..1480ea7 100644 --- a/src/periodo/periodo.service.ts +++ b/src/periodo/periodo.service.ts @@ -16,7 +16,7 @@ export class PeriodoService { } async findAll() { - return this.periodoRepository.find(); + return this.periodoRepository.find({order:{'id_periodo':"DESC"}}); } async getPeriodoActivo(): Promise { @@ -32,7 +32,7 @@ export class PeriodoService { return periodo; } - async getPeriodoActivoWhitoutError(): Promise { + async getPeriodoActivoWhitoutError(): Promise { const periodo = await this.periodoRepository.findOne({ where: { activo: true }, order: { id_periodo: 'DESC' }, @@ -45,7 +45,7 @@ export class PeriodoService { await this.periodoRepository.delete(id_periodo) } - async periodoDisable(id_periodo:number) { + async periodoDisable(id_periodo: number) { await this.periodoRepository.update(id_periodo, { activo: false }) } @@ -58,7 +58,7 @@ export class PeriodoService { const periodoActive = await this.getPeriodoActivoWhitoutError(); - if(periodoActive){ + if (periodoActive) { await this.periodoDisable(periodoActive.id_periodo) } @@ -66,7 +66,7 @@ export class PeriodoService { return this.periodoRepository.save(create) } - async modifiedDate(data:ModifiedDateDto,id_periodo){ - return this.periodoRepository.update(id_periodo,data) + async modifiedDate(data: ModifiedDateDto, id_periodo) { + return this.periodoRepository.update(id_periodo, data) } } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index cf53d40..e9945ed 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -40,14 +40,14 @@ export class UserService { const payload = { id: user.id_usuario, - usuario: user.usuario, + usuario: user.nombre, role: user.perfil.id_perfil, }; const token = await this.jwtService.signAsync(payload); res.cookie('token', token, { httpOnly: true, - secure: process.env.NODE_ENV === 'production', // en dev desactívalo + secure: process.env.NODE_ENV === 'production', sameSite: 'strict', path: '/', });