marca service final
This commit is contained in:
parent
5200cc1ba4
commit
7de9aa4046
@ -7,9 +7,9 @@ import { Marca } from './entity/marca.entity';
|
|||||||
export class MarcaService {
|
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): Promise<{ message: string }> {
|
||||||
// Buscamos una marca con ese nombre
|
// Buscamos un registro con ese nombre
|
||||||
return this.findByMarca(marca, tipo, false)
|
return this.findByMarca(marca, tipo)
|
||||||
.then((existeMarca) => {
|
.then((existeMarca) => {
|
||||||
// Sacamos error si existe
|
// Sacamos error si existe
|
||||||
if (existeMarca) throw new ConflictException('Ya existe esta marca.');
|
if (existeMarca) throw new ConflictException('Ya existe esta marca.');
|
||||||
@ -19,25 +19,20 @@ export class MarcaService {
|
|||||||
.then((_) => ({ message: 'Se creó correctamente una nueva marca.' }));
|
.then((_) => ({ message: 'Se creó correctamente una nueva marca.' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll(tipo: string) {
|
findAll(tipo: string): Promise<Marca[]> {
|
||||||
return this.repository.find({ where: { tipo }, order: { tipo: 'ASC' } });
|
return this.repository.find({ where: { tipo }, order: { tipo: 'ASC' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
findById(id_marca: number, tipo: string, validarExistencia = true) {
|
findById(id_marca: number, tipo: string): Promise<Marca> {
|
||||||
return this.repository
|
return this.repository
|
||||||
.findOne({ where: { id_marca, tipo } })
|
.findOne({ where: { id_marca, tipo } })
|
||||||
.then((marca) => {
|
.then((marca) => {
|
||||||
if (validarExistencia && !marca)
|
if (!marca) throw new ConflictException('No existe este id marca.');
|
||||||
throw new ConflictException('No existe esta marca.');
|
|
||||||
return marca;
|
return marca;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findByMarca(marca: string, tipo: string, validarExistencia = true) {
|
findByMarca(marca: string, tipo: string): Promise<Marca> {
|
||||||
return this.repository.findOne({ where: { marca, tipo } }).then((marca) => {
|
return this.repository.findOne({ where: { marca, tipo } });
|
||||||
if (validarExistencia && !marca)
|
|
||||||
throw new ConflictException('No existe esta marca.');
|
|
||||||
return marca;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,11 +190,7 @@ export class UploadFileService {
|
|||||||
institucion,
|
institucion,
|
||||||
dataEquipo.modulo,
|
dataEquipo.modulo,
|
||||||
);
|
);
|
||||||
const marca = await this.marcaService.findByMarca(
|
const marca = await this.marcaService.findByMarca(dataEquipo.marca, 'e');
|
||||||
dataEquipo.marca,
|
|
||||||
'e',
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
const modelo = await this.modeloService.findByModelo(
|
const modelo = await this.modeloService.findByModelo(
|
||||||
dataEquipo.modelo,
|
dataEquipo.modelo,
|
||||||
'e',
|
'e',
|
||||||
|
Loading…
Reference in New Issue
Block a user