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>,
|
||||
) {}
|
||||
|
||||
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<Modelo[]> {
|
||||
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
|
||||
.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<Modelo> {
|
||||
return this.repository.findOne({ where: { modelo, tipo } });
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,6 @@ export class UploadFileService {
|
||||
const modelo = await this.modeloService.findByModelo(
|
||||
dataEquipo.modelo,
|
||||
'e',
|
||||
false,
|
||||
);
|
||||
const carrito =
|
||||
tipoCarrito && modulo
|
||||
|
Loading…
Reference in New Issue
Block a user