Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bb95a3d50 | |||
| 81ad881d6a |
@@ -6,6 +6,8 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
Res,
|
Res,
|
||||||
Req,
|
Req,
|
||||||
|
Param,
|
||||||
|
Patch,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Response } from 'express';
|
import type { Response } from 'express';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
@@ -21,6 +23,12 @@ export class UserController {
|
|||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
|
|
||||||
|
@Get('/switch/:id')
|
||||||
|
async getactive(@Param('id') id:number) {
|
||||||
|
return this.userService.getactive(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async getAll() {
|
async getAll() {
|
||||||
return this.userService.getAll();
|
return this.userService.getAll();
|
||||||
@@ -33,6 +41,11 @@ export class UserController {
|
|||||||
return this.userService.getAllPerfil();
|
return this.userService.getAllPerfil();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Patch(':id/activo')
|
||||||
|
toggleActivo(@Param('id') id: number) {
|
||||||
|
return this.userService.toggleActivo(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async Login(@Body() data: Login, @Res() res: Response) {
|
async Login(@Body() data: Login, @Res() res: Response) {
|
||||||
return this.userService.Login(data, res);
|
return this.userService.Login(data, res);
|
||||||
@@ -45,7 +58,9 @@ export class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@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);
|
||||||
|
|||||||
@@ -20,6 +20,37 @@ export class UserService {
|
|||||||
private perfilRepository: Repository<Perfil>,
|
private perfilRepository: Repository<Perfil>,
|
||||||
private jwtService: JwtService,
|
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) {
|
||||||
|
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<User> {
|
async findOneByNameandPassword(data: Login): Promise<User> {
|
||||||
const { usuario, password } = data;
|
const { usuario, password } = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user