carrito incompleto
This commit is contained in:
parent
2a6d0c6219
commit
6d64637423
@ -2,7 +2,8 @@ import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { CarritoService } from './carrito.service';
|
||||
import { CarritoCreateDto } from './dto/carrito-create.dto';
|
||||
import { CarritoUpdateDto } from './dto/carrito-update.dto';
|
||||
import { CarritoGetDto } from './dto/carrtio-get-dto';
|
||||
import { CarritoGetDto } from './dto/carrito-get-dto';
|
||||
import { CarritoDto } from './dto/carrito.dto'
|
||||
|
||||
@Controller('carrito')
|
||||
export class CarritoController {
|
||||
@ -13,7 +14,6 @@ export class CarritoController {
|
||||
return this.carritoService.create(
|
||||
body.id_tipo_carrito,
|
||||
body.id_modulo,
|
||||
body.carrito,
|
||||
);
|
||||
}
|
||||
|
||||
@ -22,20 +22,14 @@ export class CarritoController {
|
||||
return this.carritoService.findAll();
|
||||
}
|
||||
|
||||
// Crear dto que solo espere el campo id_carrito
|
||||
@Get('carrito')
|
||||
carrito(@Query() query: CarritoGetDto) {
|
||||
carrito(@Query() query: CarritoDto) {
|
||||
return this.carritoService.findById(Number(query.id_carrito));
|
||||
}
|
||||
|
||||
@Get('carritos')
|
||||
carritos(@Query() query: CarritoGetDto) {
|
||||
return this.carritoService.findByIdModulo(
|
||||
Number(query.pagina),
|
||||
Number(query.id_modulo),
|
||||
Number(query.id_tipo_carrito),
|
||||
query.activo === 'true',
|
||||
);
|
||||
return this.carritoService.findByIdModulo(query);
|
||||
}
|
||||
|
||||
@Get('carritoInstitucion')
|
||||
|
@ -3,9 +3,11 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Carrito } from './entity/carrito.entity';
|
||||
import { Modulo } from '../modulo/entity/modulo.entity';
|
||||
import { InstitucionTipoCarrito } from '../institucion-tipo-carrito/entity/institucion-tipo-carrito.entity';
|
||||
import { ModuloService } from '../modulo/modulo.service';
|
||||
import { InstitucionTipoCarritoService } from '../institucion-tipo-carrito/institucion-tipo-carrito.service';
|
||||
|
||||
@ -18,20 +20,19 @@ export class CarritoService {
|
||||
) {}
|
||||
|
||||
// Eliminar carrito (argumento) de este proceso. Buscar cuantos carritos tiene el modulo de ese tipo carrito y automaticamente generar carrito
|
||||
async create(id_tipo_carrito: number, id_modulo: number, carrito: string) {
|
||||
async create(id_tipo_carrito: number, id_modulo: number) {
|
||||
const modulo = await this.moduloService.findById(id_modulo);
|
||||
const tipoCarrito =
|
||||
await this.institucionTipoCarritoService.findByIdTipoCarito(
|
||||
id_tipo_carrito,
|
||||
);
|
||||
const nuevoCarrito = this.repository.create({
|
||||
carrito,
|
||||
modulo,
|
||||
tipoCarrito,
|
||||
});
|
||||
|
||||
return this.repository
|
||||
.findOne({ carrito, modulo, tipoCarrito })
|
||||
.findOne({ modulo, tipoCarrito })
|
||||
.then((existeCarrito) => {
|
||||
if (existeCarrito)
|
||||
throw new ConflictException('Este carrito ya existe en este modulo');
|
||||
@ -54,17 +55,30 @@ export class CarritoService {
|
||||
}
|
||||
|
||||
// Toma de ejemplo la funcion que esta en /src/usuario/usuario.service.ts
|
||||
findByIdModulo(
|
||||
pagina: number,
|
||||
id_modulo: number,
|
||||
id_tipo_carrito: number,
|
||||
activo: boolean,
|
||||
) {
|
||||
return this.repository.findOne(id_modulo).then((modulo) => {
|
||||
if (!modulo)
|
||||
throw new NotFoundException('No existen carritos es este modulo');
|
||||
return modulo;
|
||||
});
|
||||
async findByIdModulo(filtros: {
|
||||
pagina?: string,
|
||||
id_modulo?: string,
|
||||
id_tipo_carrito?: string,
|
||||
activo?: string,
|
||||
}) {
|
||||
const busqueda: {
|
||||
modulo?: Modulo;
|
||||
institucionTipoCarrito?: InstitucionTipoCarrito;
|
||||
activo?: string;
|
||||
} = {}
|
||||
|
||||
const modulo = filtros.id_modulo
|
||||
? await this.moduloService.findById(Number(filtros.id_modulo))
|
||||
: null;
|
||||
const institucionTipoCarrito = filtros.id_tipo_carrito
|
||||
? await this.institucionTipoCarritoService.findById(Number(filtros.id_tipo_carrito))
|
||||
: null
|
||||
|
||||
if (filtros.activo) busqueda.activo = filtros.activo;
|
||||
if (modulo) busqueda.modulo = modulo;
|
||||
if (institucionTipoCarrito) busqueda.institucionTipoCarrito = institucionTipoCarrito;
|
||||
//falta página
|
||||
return this.repository.find(busqueda);
|
||||
}
|
||||
|
||||
// re hacer
|
||||
|
20
src/carrito/dto/carrito-get-dto.ts
Normal file
20
src/carrito/dto/carrito-get-dto.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { IsBooleanString, IsNumberString, IsOptional } from 'class-validator';
|
||||
|
||||
export class CarritoGetDto {
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_carrito?: string;
|
||||
|
||||
@IsNumberString()
|
||||
id_tipo_carrito: string;
|
||||
|
||||
@IsNumberString()
|
||||
id_modulo: string;
|
||||
|
||||
@IsBooleanString()
|
||||
@IsOptional()
|
||||
activo?: string;
|
||||
}
|
6
src/carrito/dto/carrito.dto.ts
Normal file
6
src/carrito/dto/carrito.dto.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { IsNumberString, } from 'class-validator';
|
||||
|
||||
export class CarritoDto {
|
||||
@IsNumberString()
|
||||
id_carrito: string;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class CarritoGetDto {
|
||||
// Cambiar por IsNumberString, en todas
|
||||
@IsString()
|
||||
pagina: string;
|
||||
|
||||
// De aqui para abajo agregar IsOptional y operadro ?
|
||||
@IsString()
|
||||
id_carrito: string;
|
||||
|
||||
@IsString()
|
||||
id_tipo_carrito: string;
|
||||
|
||||
@IsString()
|
||||
id_modulo: string;
|
||||
|
||||
// Cambiat por IsBooleanString
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
activo?: string;
|
||||
}
|
Loading…
Reference in New Issue
Block a user