93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
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';
|
|
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, RolesGuard)
|
|
@Get()
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
|
findAll(): Promise<Equipo[]> {
|
|
return this.equipoService.findAll();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
|
@Get('/active')
|
|
findActive() {
|
|
return this.equipoService.findActive();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
|
@Get('/disable')
|
|
findDisable() {
|
|
return this.equipoService.findDisable();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
|
@Get('/student/:id')
|
|
findOnlyUsable(@Param('id') id: number): Promise<Equipo[]> {
|
|
return this.equipoService.findOnlyUsable(+id);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
|
@Get('/busy')
|
|
findOnlyBusy(): Promise<Equipo[]> {
|
|
return this.equipoService.findOnlyBusy();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string): Promise<Equipo> {
|
|
return this.equipoService.findOne(id);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
|
@Post()
|
|
create(@Body() equipo: CreateEquipoDto) {
|
|
return this.equipoService.create(equipo);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
|
@Patch()
|
|
update(@Body() equipo: CreateEquipoDto) {
|
|
return this.equipoService.update(equipo);
|
|
}
|
|
|
|
@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, RolesGuard)
|
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
|
@Patch('actualizar-area')
|
|
actualizarPorArea(
|
|
@Body() updateAreaEquiposDto: UpdateAreaEquiposDto,
|
|
) {
|
|
const { id_area_ubicacion, activo } = updateAreaEquiposDto;
|
|
|
|
return this.equipoService.actualizarEquiposPorArea(
|
|
id_area_ubicacion,
|
|
activo,
|
|
);
|
|
}
|
|
|
|
}
|
|
//IO
|