listo marca y modelo

This commit is contained in:
xXpuma99Xx 2022-10-24 14:51:04 -05:00
parent ace8e16c83
commit d78f9446cc
2 changed files with 8 additions and 6 deletions

View File

@ -8,14 +8,15 @@ export class MarcaService {
constructor(@InjectRepository(Marca) private repository: Repository<Marca>) {} constructor(@InjectRepository(Marca) private repository: Repository<Marca>) {}
create(marca: string, tipo: string) { create(marca: string, tipo: string) {
// Busco una marca con ese nombre
return this.findByMarca(marca, tipo, false) return this.findByMarca(marca, tipo, false)
.then((existeMarca) => { .then((existeMarca) => {
// Saco error si existe
if (existeMarca) throw new ConflictException('Ya existe esta marca.'); if (existeMarca) throw new ConflictException('Ya existe esta marca.');
// Creo y guardo el registro
return this.repository.save(this.repository.create({ marca, tipo })); return this.repository.save(this.repository.create({ marca, tipo }));
}) })
.then((_) => ({ .then((_) => ({ message: 'Se creó correctamente una nueva marca.' }));
message: 'Se creó correctamente una nueva marca.',
}));
} }
findAll(tipo: string) { findAll(tipo: string) {

View File

@ -10,14 +10,15 @@ export class ModeloService {
) {} ) {}
create(modelo: string, tipo: string) { create(modelo: string, tipo: string) {
// Busco un modelo con ese nombre
return this.findByModelo(modelo, tipo, false) return this.findByModelo(modelo, tipo, false)
.then((existeModelo) => { .then((existeModelo) => {
// Saco error si existe
if (existeModelo) throw new ConflictException('Ya existe este modelo.'); if (existeModelo) throw new ConflictException('Ya existe este modelo.');
// Creo y guardo el registro
return this.repository.save(this.repository.create({ modelo, tipo })); return this.repository.save(this.repository.create({ modelo, tipo }));
}) })
.then((_) => ({ .then((_) => ({ message: 'Se creó correctamente un nuevo modelo.' }));
message: 'Se creó correctamente un nuevo modelo.',
}));
} }
findAll(tipo: string) { findAll(tipo: string) {