From 81ad881d6a1f2b16c0e1549ea7bc16ccf6207041 Mon Sep 17 00:00:00 2001 From: frcarlos <307100636@pcpuma.acatlan.unam.mx> Date: Wed, 4 Mar 2026 14:20:47 -0500 Subject: [PATCH 1/2] merge --- src/user/user.controller.ts | 9 +++++++++ src/user/user.service.ts | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index e6e1b9d..29b3ca1 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -6,6 +6,7 @@ import { UseGuards, Res, Req, + Param, } from '@nestjs/common'; import type { Response } from 'express'; import { UserService } from './user.service'; @@ -21,6 +22,12 @@ export class UserController { @UseGuards(JwtAuthGuard, RolesGuard) @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) + + @Get('/switch/:id') + async getactive(@Param('id') id:number) { + return this.userService.getactive(id); + } + @Get() async getAll() { return this.userService.getAll(); @@ -45,7 +52,9 @@ export class UserController { } @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) + @Post('/create') async createUser(@Body() data: CreateUserDto) { return this.userService.create(data); diff --git a/src/user/user.service.ts b/src/user/user.service.ts index e9945ed..e7443a4 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -21,6 +21,21 @@ export class UserService { private jwtService: JwtService, ) {} + +async getactive(id: number) { + const user = await this.userRepository.findOne({ + where: { id_usuario: id }, + }); + + if (!user) { + throw new NotFoundException('Usuario no encontrado'); + } + + user.activo = user.activo === 1 ? 0 : 1; + + return this.userRepository.save(user); +} + async findOneByNameandPassword(data: Login): Promise { const { usuario, password } = data; From 3bb95a3d50d13a758af054fe79f82212c3f1fbb5 Mon Sep 17 00:00:00 2001 From: frcarlos <307100636@pcpuma.acatlan.unam.mx> Date: Thu, 5 Mar 2026 14:41:19 -0500 Subject: [PATCH 2/2] @Patch idactivo --- src/user/user.controller.ts | 6 ++++++ src/user/user.service.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 29b3ca1..4821d8b 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -7,6 +7,7 @@ import { Res, Req, Param, + Patch, } from '@nestjs/common'; import type { Response } from 'express'; import { UserService } from './user.service'; @@ -40,6 +41,11 @@ export class UserController { return this.userService.getAllPerfil(); } +@Patch(':id/activo') +toggleActivo(@Param('id') id: number) { + return this.userService.toggleActivo(id); +} + @Post() async Login(@Body() data: Login, @Res() res: Response) { return this.userService.Login(data, res); diff --git a/src/user/user.service.ts b/src/user/user.service.ts index e7443a4..cb9741d 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -20,6 +20,22 @@ export class UserService { private perfilRepository: Repository, private jwtService: JwtService, ) {} + async toggleActivo(id: number) { + + const usuario = await this.userRepository.findOne({ + where: { id_usuario: id } + }); + + + if(!usuario){ + throw new NotFoundException("no se encontro usuario") +} + + + usuario.activo = usuario.activo === 1 ? 0 : 1; + + return this.userRepository.save(usuario); +} async getactive(id: number) {