Compare commits
2 Commits
Carlos
..
e28d534edf
| Author | SHA1 | Date | |
|---|---|---|---|
| e28d534edf | |||
| 54d878c145 |
@@ -11,26 +11,33 @@ export class MesaController {
|
||||
constructor(private readonly mesaService: MesaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
async findAll() {
|
||||
return this.mesaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('activo')
|
||||
async findAllActivo() {
|
||||
return this.mesaService.findAllActivo();
|
||||
}
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('uso')
|
||||
async findActiveMesas() {
|
||||
return this.mesaService.findActiveMesas();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('usoWhitout')
|
||||
async findActiveMesasWhitoudOcupado() {
|
||||
return this.mesaService.findActiveMesasWhitoudOcupado();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id')
|
||||
@@ -42,7 +49,7 @@ export class MesaController {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@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);
|
||||
|
||||
@@ -142,4 +142,27 @@ export class MesaService {
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
findActiveMesasWhitoudOcupado() {
|
||||
return this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
.select([
|
||||
'mesa.id_mesa AS id_mesa',
|
||||
])
|
||||
.where('mesa.activo = 1')
|
||||
.andWhere(`
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM bitacora_mesa bm
|
||||
WHERE bm.id_mesa = mesa.id_mesa
|
||||
AND TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bm.tiempo_entrada, INTERVAL bm.tiempo_asignado MINUTE)
|
||||
) > 0
|
||||
)
|
||||
`)
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
UseGuards,
|
||||
Res,
|
||||
Req,
|
||||
Param,
|
||||
Patch,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
@@ -21,13 +19,6 @@ import { Role } from 'src/role.enum';
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) { }
|
||||
|
||||
@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() {
|
||||
@@ -41,11 +32,6 @@ 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);
|
||||
@@ -58,9 +44,7 @@ toggleActivo(@Param('id') id: number) {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
|
||||
@@ -20,37 +20,6 @@ export class UserService {
|
||||
private perfilRepository: Repository<Perfil>,
|
||||
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> {
|
||||
const { usuario, password } = data;
|
||||
@@ -59,6 +28,10 @@ async getactive(id: number) {
|
||||
where: { usuario, password },
|
||||
});
|
||||
|
||||
if(user?.activo === 0){
|
||||
throw new NotFoundException(`El usuario se encuentra desactivado`);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user