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