se modificó endpoint y base de datps
This commit is contained in:
@@ -11,7 +11,8 @@ export class CreateEquipoDto {
|
||||
inventario: string;
|
||||
|
||||
@IsString()
|
||||
serie: string;
|
||||
@IsOptional()
|
||||
serie?: string;
|
||||
|
||||
@IsString()
|
||||
lugar: string;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Equipo } from './equipo.entity';
|
||||
@@ -45,7 +46,7 @@ export class Estado {
|
||||
|
||||
@Entity()
|
||||
export class Adscripcion {
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryColumn()
|
||||
id_adscripcion: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 300 })
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Post,
|
||||
Res,
|
||||
Request,
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
@@ -20,7 +21,7 @@ import type { Response } from 'express';
|
||||
|
||||
@Controller('equipos')
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) {}
|
||||
constructor(private readonly equipoService: EquipoService) { }
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('buscar')
|
||||
async buscarEquipos(
|
||||
@@ -123,12 +124,11 @@ export class EquipoController {
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('reporte')
|
||||
async reporte(@Res() res: Response) {
|
||||
async reporte() {
|
||||
try {
|
||||
await this.equipoService.generar_reporte();
|
||||
return await this.equipoService.generar_reporte();
|
||||
} catch (error) {
|
||||
console.error('Error al generar el Excel:', error);
|
||||
res.status(500).send('Error al generar el archivo Excel');
|
||||
throw new BadRequestException('Error al generar el Excel:', error);
|
||||
}
|
||||
}
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
@@ -55,7 +55,7 @@ export class EquipoService {
|
||||
|
||||
@InjectRepository(ProcesadorTipoEquipo)
|
||||
private readonly procesadorTipoEquipoRepo: Repository<ProcesadorTipoEquipo>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async buscarEquipos(filtros: any, page: number = 1, limit: number = 10) {
|
||||
const query = this.equipoRepository
|
||||
@@ -233,13 +233,13 @@ export class EquipoService {
|
||||
where: { inventario: equipo.inventario },
|
||||
});
|
||||
if (equipoExixtente) {
|
||||
throw new Error('El equipo ya existe');
|
||||
throw new BadRequestException('El equipo ya existe');
|
||||
}
|
||||
|
||||
if (equipo.isImpresora) {
|
||||
nuevoEquipo = this.equipoRepository.create({
|
||||
inventario: equipo.inventario,
|
||||
serie: equipo.serie,
|
||||
serie: equipo.serie ? equipo.serie : undefined,
|
||||
lugar: equipo.lugar,
|
||||
fechaFactura: equipo.fechaFactura,
|
||||
antiguedad: equipo.antiguedad,
|
||||
@@ -334,6 +334,14 @@ export class EquipoService {
|
||||
return this.exportToClient(objectParse, res);
|
||||
}
|
||||
|
||||
async createReport() {
|
||||
let obj = await this.generar_reporte();
|
||||
const objectParse = Array.isArray(obj)
|
||||
? obj.map((item) => this.flattenObject(item))
|
||||
: [this.flattenObject(obj)];
|
||||
return objectParse;
|
||||
}
|
||||
|
||||
async contar_tipoEquipos_tipoUso(): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
|
||||
Reference in New Issue
Block a user