institucion tipo carrito mejorado
This commit is contained in:
parent
1513b4a2f0
commit
c746b44f69
@ -3,7 +3,7 @@ import { InstitucionTipoCarritoService } from './institucion-tipo-carrito.servic
|
||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||
import { InstitucionTipoCarritoCreateDto } from './dto/institucion-tipo-carrito-create.dto';
|
||||
import { InstitucionTipoCarritoUpdateDto } from './dto/institucion-tipo-carrito-update.dto';
|
||||
import {ApiTags} from '@nestjs/swagger'
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('institucion-tipo-carrito')
|
||||
@ApiTags('institucion-tipo-carrito')
|
||||
@ -25,14 +25,14 @@ export class InstitucionTipoCarritoController {
|
||||
return this.institucionTipoCarritoService.findAll();
|
||||
}
|
||||
|
||||
@Get('institucion_tipos_carritos')
|
||||
@Get('tipos_carritos')
|
||||
institucionTiposCarritos(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionTipoCarritoService.findAllByIdInstitucion(
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@Get('institucion_tipos_carritos_mostar')
|
||||
@Get('tipos_carritos_mostar')
|
||||
institucionTiposCarritosMostrar(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionTipoCarritoService.findAllByIdInstitucionMostar(
|
||||
parseInt(query.id_institucion),
|
||||
|
@ -5,6 +5,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Institucion } from 'src/institucion/entity/institucion.entity';
|
||||
import { InstitucionTipoCarrito } from './entity/institucion-tipo-carrito.entity';
|
||||
import { TipoCarrito } from './entity/tipo-carrito.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
@ -20,9 +21,8 @@ export class InstitucionTipoCarritoService {
|
||||
) {}
|
||||
|
||||
create(letra: string, tipo_carrito: string) {
|
||||
/** Checar que no este usando la letra ni el nombre */
|
||||
return this.repositoryTipoCarrito
|
||||
.findOne({ letra, tipo_carrito })
|
||||
.findOne({ where: [{ letra }, { tipo_carrito }] })
|
||||
.then((existeTipoCarrito) => {
|
||||
if (existeTipoCarrito) {
|
||||
if (letra === existeTipoCarrito.letra)
|
||||
@ -56,23 +56,20 @@ export class InstitucionTipoCarritoService {
|
||||
return this.repositoryTipoCarrito.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
findAllByIdInstitucion(id_institucion: number, mostrar = false) {
|
||||
const busqueda: { institucion?: Institucion; mostrar?: boolean } = {};
|
||||
|
||||
if (mostrar) busqueda.mostrar = mostrar;
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.repositoryInstitucionTipoCarrito.find({ institucion }),
|
||||
);
|
||||
.then((institucion) => {
|
||||
busqueda.institucion = institucion;
|
||||
return this.repositoryInstitucionTipoCarrito.find(busqueda);
|
||||
});
|
||||
}
|
||||
|
||||
findAllByIdInstitucionMostar(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.repositoryInstitucionTipoCarrito.find({
|
||||
institucion,
|
||||
mostrar: true,
|
||||
}),
|
||||
);
|
||||
return this.findAllByIdInstitucion(id_institucion, true);
|
||||
}
|
||||
|
||||
findById(id_institucion_tipo_carrito) {
|
||||
@ -94,11 +91,9 @@ export class InstitucionTipoCarritoService {
|
||||
.findOne({ id_tipo_carrito })
|
||||
.then((tipoCarrito) => {
|
||||
if (!tipoCarrito)
|
||||
throw new NotFoundException(
|
||||
'No existe este tipo carrito.',
|
||||
);
|
||||
throw new NotFoundException('No existe este tipo carrito.');
|
||||
return tipoCarrito;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
update(attrs: Partial<InstitucionTipoCarrito>) {
|
||||
|
Loading…
Reference in New Issue
Block a user