367 lines
9.6 KiB
TypeScript
367 lines
9.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Body,
|
|
Patch,
|
|
Param,
|
|
ParseIntPipe,
|
|
UseGuards,
|
|
Get,
|
|
Query,
|
|
Delete,
|
|
HttpCode,
|
|
HttpStatus,
|
|
NotFoundException,
|
|
Post,
|
|
Res,
|
|
Request,
|
|
BadRequestException,
|
|
} from '@nestjs/common';
|
|
import { EquipoService } from './equipo.service';
|
|
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { Equipo } from './entities/equipo.entity';
|
|
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
|
import type { Response } from 'express';
|
|
|
|
@Controller('equipos')
|
|
export class EquipoController {
|
|
constructor(private readonly equipoService: EquipoService) {}
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('buscar')
|
|
async buscarEquipos(
|
|
@Query() filtros: any,
|
|
@Query('page') page: number = 1,
|
|
@Query('limit') limit: number = 10,
|
|
) {
|
|
return this.equipoService.buscarEquipos(filtros, +page, +limit);
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('buscar/:inv')
|
|
async serch(@Param('inv') inv: string) {
|
|
return await this.equipoService.findEquipo(inv);
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Post('crear')
|
|
async create(@Body() Equipo: CreateEquipoDto, @Request() req) {
|
|
return await this.equipoService.create(Equipo, req.user.id);
|
|
}
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Patch('update/:id')
|
|
update(
|
|
@Request() req,
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Body() equipoNuevo: UpdateEquipoDto,
|
|
) {
|
|
return this.equipoService.updateEquipo(equipoNuevo, id, req.user.id);
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Delete(':id')
|
|
async deleteEquipo(@Param('id', ParseIntPipe) id_equipo: string) {
|
|
try {
|
|
return await this.equipoService.deleteEquipo(id_equipo);
|
|
} catch (error) {
|
|
throw new NotFoundException(error.message);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('usos')
|
|
findUsos() {
|
|
return this.equipoService.findAllUsos();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('marcas')
|
|
findMarcas() {
|
|
return this.equipoService.findAllMarcas();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('estados')
|
|
findEstados() {
|
|
return this.equipoService.findAllEstados();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('adscripciones')
|
|
findAdscripciones() {
|
|
return this.equipoService.findAllAdscripciones();
|
|
}
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('tipos-equipo')
|
|
findTiposEquipo() {
|
|
return this.equipoService.findAllTiposEquipo();
|
|
}
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('sistemas-operativos')
|
|
findSistemasOperativos() {
|
|
return this.equipoService.findAllSistemasOperativos();
|
|
}
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('procesadores')
|
|
findProcesadores() {
|
|
return this.equipoService.findAllProcesadores();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('laboratorios')
|
|
findLaboratorios() {
|
|
return this.equipoService.findAllLaboratorios();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('proyectos')
|
|
findProyectos() {
|
|
return this.equipoService.findAllProyectos();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('perifericos')
|
|
findPerifericos() {
|
|
return this.equipoService.findAllPerifericos();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('procesador-tipo-equipos')
|
|
findProcesadorTipoEquipos() {
|
|
return this.equipoService.findAllProcesadorTipoEquipos();
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporteXLSX')
|
|
async generarReporte(@Res() res: Response) {
|
|
try {
|
|
await this.equipoService.createEcxel(res);
|
|
} catch (error) {
|
|
console.error('Error al generar el Excel:', error);
|
|
res.status(500).send('Error al generar el archivo Excel');
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte')
|
|
async reporte() {
|
|
try {
|
|
return await this.equipoService.generar_reporte();
|
|
} catch (error) {
|
|
throw new BadRequestException('Error al generar el reporte:', error);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/tipoEquipos_tipoUso')
|
|
async reportetipoEquipos_tipoUso() {
|
|
try {
|
|
return await this.equipoService.contar_tipoEquipos_tipoUso();
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte tipoEquipos_tipoUso:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/tipoEquipos_sistemasOperativos')
|
|
async reportetipoEquipos_sistemasOperativos() {
|
|
try {
|
|
return await Promise.all([
|
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(equpos_pc),
|
|
this.equipoService.contar_tipoEquipos_sistemasOperativos([
|
|
estritorio_mac,
|
|
]),
|
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(portatiles),
|
|
this.equipoService.contar_tipoEquipos_sistemasOperativos([
|
|
portatiles_mac,
|
|
]),
|
|
this.equipoService.contar_tipoEquipos_sistemasOperativos([servidor]),
|
|
]);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte tipoEquipos_sistemasOperativos:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/tipoEquipos_procesador')
|
|
async reportetipoEquipos_procesador() {
|
|
try {
|
|
return await Promise.all([
|
|
this.equipoService.contar_tipoEquipos_procesador(equpos_pc),
|
|
this.equipoService.contar_tipoEquipos_procesador([estritorio_mac]),
|
|
this.equipoService.contar_tipoEquipos_procesador(portatiles),
|
|
this.equipoService.contar_tipoEquipos_procesador([portatiles_mac]),
|
|
this.equipoService.contar_tipoEquipos_procesador([servidor]),
|
|
]);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte tipoEquipos_procesador:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/tipoEquipos_antiguedad')
|
|
async reportetipoEquipos_antiguedad() {
|
|
try {
|
|
return await this.equipoService.contar_tipoEquipos_antiguedad();
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte contar_tipoEquipos_antiguedad:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/garantia')
|
|
async reportegarantia() {
|
|
try {
|
|
return await Promise.all([
|
|
this.equipoService.garantia(escritorio),
|
|
this.equipoService.garantia(portatil),
|
|
this.equipoService.garantia([servidor]),
|
|
]);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte garantia:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/equipos_impesion_group/impresoras')
|
|
async reporteequipos_impesion_group() {
|
|
try {
|
|
return await this.equipoService.equipos_impesion_group(impresoras);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte impesion_group impresoras:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/equipos_impesion_group/dijitales')
|
|
async reporteequipos_impesion_group_dijitales() {
|
|
try {
|
|
return await this.equipoService.equipos_impesion_group(dijitales);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte impesion_group dijitales:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/contar_periferico_tipoUso/impresoras')
|
|
async reporte_contar_periferico_tipoUso_impresoras() {
|
|
try {
|
|
return await this.equipoService.contar_periferico_tipoUso(impresoras);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte periferico_tipoUso impresoras:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/contar_periferico_tipoUso/dijtales')
|
|
async reporte_contar_periferico_tipoUso_dijtales() {
|
|
try {
|
|
return await this.equipoService.contar_periferico_tipoUso(dijitales);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte periferico_tipoUso dijtales:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/contar_perifericos_antiguedad')
|
|
async reporte_contar_perifericos_antiguedad() {
|
|
try {
|
|
return await this.equipoService.contar_perifericos_antiguedad(
|
|
impresoras,
|
|
dijitales,
|
|
);
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte perifericos_antiguedad:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/contar_laboratorio')
|
|
async reporte_contar_laboratorio() {
|
|
try {
|
|
return await this.equipoService.laboratorio_equipos();
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte perifericos_antiguedad:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Get('reporte/contar_proyecto')
|
|
async reporte_contar_proyecto() {
|
|
try {
|
|
return await this.equipoService.proyecto_equipos();
|
|
} catch (error) {
|
|
throw new BadRequestException(
|
|
'Error al generar el reporte perifericos_antiguedad:',
|
|
error,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
let escritorio = ['ESCRITORIO PC', 'ESCRITORIO MAC OS ', 'ESCRITORIO LINUX'];
|
|
let portatil = [
|
|
'PORTÁTILES WINDOWS',
|
|
'PORTÁTILES CHROMEBOOK',
|
|
'PORTÁTILES MAC OS',
|
|
];
|
|
|
|
let equipos_mac = ['ESCRITORIO MAC OS ', 'PORTÁTILES MAC OS'];
|
|
|
|
let equpos_pc = ['ESCRITORIO PC', 'ESCRITORIO LINUX'];
|
|
let estritorio_mac = 'ESCRITORIO MAC OS ';
|
|
let portatiles_mac = 'PORTÁTILES MAC OS';
|
|
|
|
let portatiles = ['PORTÁTILES WINDOWS', 'PORTÁTILES CHROMEBOOK'];
|
|
|
|
let tabletas = ['TABLETA ANDROID', 'TABLETA iPAD OS'];
|
|
|
|
let impresoras = [
|
|
'INYECCIÓN TINTA',
|
|
'LÁSER DE ALTO VOLUMEN B/N',
|
|
'LÁSER PEQUEÑA B/N',
|
|
'LÁSER PEQUEÑA COLOR',
|
|
'MATRIZ DE PUNTOS',
|
|
'MULTIFUNCIONALES',
|
|
'3D',
|
|
];
|
|
|
|
let dijitales = [
|
|
'DIGITALIZADOR DE CAMA PLANA PARA OFICINA',
|
|
'DIGITALIZADOR CON ALIMENTADOR DE HOJAS PARA OFICINA',
|
|
];
|
|
|
|
let servidor = 'SERVIDOR';
|