From fd8592872c0d5d024f42de7121d493422fdf47f7 Mon Sep 17 00:00:00 2001 From: lemuel Date: Fri, 23 Dec 2022 08:02:20 -0600 Subject: [PATCH] modelo service final --- src/modelo/modelo.service.ts | 24 +++++++++--------------- src/upload-file/upload-file.service.ts | 1 - 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/modelo/modelo.service.ts b/src/modelo/modelo.service.ts index e9b4b60..68888e0 100644 --- a/src/modelo/modelo.service.ts +++ b/src/modelo/modelo.service.ts @@ -9,9 +9,9 @@ export class ModeloService { @InjectRepository(Modelo) private repository: Repository, ) {} - create(modelo: string, tipo: string) { - // Buscamos un modelo con ese nombre - return this.findByModelo(modelo, tipo, false) + create(modelo: string, tipo: string): Promise<{ message: string }> { + // Buscamos un registro con ese nombre + return this.findByModelo(modelo, tipo) .then((existeModelo) => { // Sacamos error si existe if (existeModelo) throw new ConflictException('Ya existe este modelo.'); @@ -21,26 +21,20 @@ export class ModeloService { .then((_) => ({ message: 'Se creó correctamente un nuevo modelo.' })); } - findAll(tipo: string) { + findAll(tipo: string): Promise { return this.repository.find({ where: { tipo }, order: { tipo: 'ASC' } }); } - findById(id_modelo: number, tipo: string, validarExistencia = true) { + findById(id_modelo: number, tipo: string): Promise { return this.repository .findOne({ where: { id_modelo, tipo } }) .then((modelo) => { - if (validarExistencia && !modelo) - throw new ConflictException('No existe este modelo.'); + if (!modelo) throw new ConflictException('No existe este modelo.'); return modelo; }); } - findByModelo(modelo: string, tipo: string, validarExistencia = true) { - return this.repository - .findOne({ where: { modelo, tipo } }) - .then((modelo) => { - if (validarExistencia && !modelo) - throw new ConflictException('No existe este modelo.'); - return modelo; - }); + + findByModelo(modelo: string, tipo: string): Promise { + return this.repository.findOne({ where: { modelo, tipo } }); } } diff --git a/src/upload-file/upload-file.service.ts b/src/upload-file/upload-file.service.ts index 970c9c3..1cfd1f7 100644 --- a/src/upload-file/upload-file.service.ts +++ b/src/upload-file/upload-file.service.ts @@ -194,7 +194,6 @@ export class UploadFileService { const modelo = await this.modeloService.findByModelo( dataEquipo.modelo, 'e', - false, ); const carrito = tipoCarrito && modulo