modelo service final
This commit is contained in:
parent
d25d69a953
commit
fd8592872c
@ -9,9 +9,9 @@ export class ModeloService {
|
|||||||
@InjectRepository(Modelo) private repository: Repository<Modelo>,
|
@InjectRepository(Modelo) private repository: Repository<Modelo>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
create(modelo: string, tipo: string) {
|
create(modelo: string, tipo: string): Promise<{ message: string }> {
|
||||||
// Buscamos un modelo con ese nombre
|
// Buscamos un registro con ese nombre
|
||||||
return this.findByModelo(modelo, tipo, false)
|
return this.findByModelo(modelo, tipo)
|
||||||
.then((existeModelo) => {
|
.then((existeModelo) => {
|
||||||
// Sacamos error si existe
|
// Sacamos error si existe
|
||||||
if (existeModelo) throw new ConflictException('Ya existe este modelo.');
|
if (existeModelo) throw new ConflictException('Ya existe este modelo.');
|
||||||
@ -21,26 +21,20 @@ export class ModeloService {
|
|||||||
.then((_) => ({ message: 'Se creó correctamente un nuevo modelo.' }));
|
.then((_) => ({ message: 'Se creó correctamente un nuevo modelo.' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll(tipo: string) {
|
findAll(tipo: string): Promise<Modelo[]> {
|
||||||
return this.repository.find({ where: { tipo }, order: { tipo: 'ASC' } });
|
return this.repository.find({ where: { tipo }, order: { tipo: 'ASC' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
findById(id_modelo: number, tipo: string, validarExistencia = true) {
|
findById(id_modelo: number, tipo: string): Promise<Modelo> {
|
||||||
return this.repository
|
return this.repository
|
||||||
.findOne({ where: { id_modelo, tipo } })
|
.findOne({ where: { id_modelo, tipo } })
|
||||||
.then((modelo) => {
|
.then((modelo) => {
|
||||||
if (validarExistencia && !modelo)
|
if (!modelo) throw new ConflictException('No existe este modelo.');
|
||||||
throw new ConflictException('No existe este modelo.');
|
|
||||||
return modelo;
|
return modelo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
findByModelo(modelo: string, tipo: string, validarExistencia = true) {
|
|
||||||
return this.repository
|
findByModelo(modelo: string, tipo: string): Promise<Modelo> {
|
||||||
.findOne({ where: { modelo, tipo } })
|
return this.repository.findOne({ where: { modelo, tipo } });
|
||||||
.then((modelo) => {
|
|
||||||
if (validarExistencia && !modelo)
|
|
||||||
throw new ConflictException('No existe este modelo.');
|
|
||||||
return modelo;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,6 @@ export class UploadFileService {
|
|||||||
const modelo = await this.modeloService.findByModelo(
|
const modelo = await this.modeloService.findByModelo(
|
||||||
dataEquipo.modelo,
|
dataEquipo.modelo,
|
||||||
'e',
|
'e',
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
const carrito =
|
const carrito =
|
||||||
tipoCarrito && modulo
|
tipoCarrito && modulo
|
||||||
|
Loading…
Reference in New Issue
Block a user