carrito input y output dto
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { CarritoService } from './carrito.service';
|
||||
import { CarritoCreateDto } from './dto/carrito-create.dto';
|
||||
import { CarritoUpdateDto } from './dto/carrito-update.dto';
|
||||
import { CarritoCarritosDto } from './dto/carrito-carritos-dto';
|
||||
import { CarritoDto } from './dto/carrito.dto';
|
||||
import { CarritoDto } from './dto/input/carrito.dto';
|
||||
import { CarritosDto } from './dto/input/carritos.dto';
|
||||
import { CreateCarritoDto } from './dto/input/create.dto';
|
||||
import { UpdateCarritoDto } from './dto/input/update.dto';
|
||||
import { CarritoOutputDto } from './dto/output/carrito.dto';
|
||||
import { CarritosOutputDto } from './dto/output/carritos.dto';
|
||||
|
||||
@Controller('carrito')
|
||||
@ApiTags('carrito')
|
||||
export class CarritoController {
|
||||
constructor(private carritoService: CarritoService) {}
|
||||
|
||||
@Serealize(CarritoOutputDto)
|
||||
@Get('carrito')
|
||||
@ApiOperation({
|
||||
description: 'Endpoint que retorna la información de un carrito.',
|
||||
@@ -24,6 +28,7 @@ export class CarritoController {
|
||||
return this.carritoService.findById(parseInt(query.id_carrito));
|
||||
}
|
||||
|
||||
@Serealize(CarritosOutputDto)
|
||||
@Get('carritos')
|
||||
@ApiOperation({
|
||||
description:
|
||||
@@ -64,7 +69,7 @@ export class CarritoController {
|
||||
type: 'string',
|
||||
required: false,
|
||||
})
|
||||
carritos(@Query() query: CarritoCarritosDto) {
|
||||
carritos(@Query() query: CarritosDto) {
|
||||
return this.carritoService.findAll(query);
|
||||
}
|
||||
|
||||
@@ -80,7 +85,7 @@ export class CarritoController {
|
||||
},
|
||||
},
|
||||
})
|
||||
create(@Body() body: CarritoCreateDto) {
|
||||
create(@Body() body: CreateCarritoDto) {
|
||||
return this.carritoService.create(
|
||||
body.id_modulo,
|
||||
body.id_tipo_carrito,
|
||||
@@ -110,7 +115,7 @@ export class CarritoController {
|
||||
},
|
||||
},
|
||||
})
|
||||
update(@Body() body: CarritoUpdateDto) {
|
||||
update(@Body() body: UpdateCarritoDto) {
|
||||
return this.carritoService.update(
|
||||
body,
|
||||
body.id_modulo,
|
||||
|
||||
@@ -68,13 +68,6 @@ export class CarritoService {
|
||||
});
|
||||
}
|
||||
|
||||
findById(id_carrito: number) {
|
||||
return this.repository.findOne({ id_carrito }).then((carrito) => {
|
||||
if (!carrito) throw new NotFoundException('No existe este carrito.');
|
||||
return carrito;
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
activo?: string;
|
||||
@@ -108,12 +101,23 @@ export class CarritoService {
|
||||
if (institucion) busqueda.modulo = { institucion };
|
||||
if (modulo) busqueda.modulo = modulo;
|
||||
return this.repository.findAndCount({
|
||||
join: {
|
||||
alias: 'c',
|
||||
innerJoinAndSelect: { m: 'c.modulo', i: 'm.institucion' },
|
||||
},
|
||||
where: busqueda,
|
||||
skip: (parseInt(filtros.pagina) - 1) * 25,
|
||||
take: 25,
|
||||
});
|
||||
}
|
||||
|
||||
findById(id_carrito: number) {
|
||||
return this.repository.findOne({ id_carrito }).then((carrito) => {
|
||||
if (!carrito) throw new NotFoundException('No existe este carrito.');
|
||||
return carrito;
|
||||
});
|
||||
}
|
||||
|
||||
async findCarrito(
|
||||
id_modulo: number | Modulo,
|
||||
id_tipo_carrito: number | TipoCarrito,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CarritoCarritosDto {
|
||||
export class CarritosDto {
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CarritoCreateDto {
|
||||
export class CreateCarritoDto {
|
||||
@IsNumber()
|
||||
id_modulo: number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IsBoolean, IsInt, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class CarritoUpdateDto {
|
||||
export class UpdateCarritoDto {
|
||||
@IsInt()
|
||||
id_carrito: number;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { ModuloOutputDto } from '../../../modulo/dto/output/modulo.dto';
|
||||
import { TipoCarritoOutputDto } from '../../../institucion-tipo-carrito/dto/output/tipo-carrito.dto';
|
||||
|
||||
export class CarritoOutputDto {
|
||||
@Expose()
|
||||
id_carrito;
|
||||
|
||||
@Expose()
|
||||
carrito;
|
||||
|
||||
@Expose()
|
||||
activo;
|
||||
|
||||
@Expose()
|
||||
marca;
|
||||
|
||||
@Expose()
|
||||
modelo;
|
||||
|
||||
@Type(() => ModuloOutputDto)
|
||||
@Expose()
|
||||
modulo;
|
||||
|
||||
@Type(() => TipoCarritoOutputDto)
|
||||
@Expose()
|
||||
tipoCarrito;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { TipoCarritoOutputDto } from '../../../institucion-tipo-carrito/dto/output/tipo-carrito.dto';
|
||||
import { ModulosOutputDto } from '../../../modulo/dto/output/modulos.dto';
|
||||
|
||||
export class CarritosOutputDto {
|
||||
@Expose()
|
||||
id_carrito;
|
||||
|
||||
@Expose()
|
||||
carrito;
|
||||
|
||||
@Expose()
|
||||
activo;
|
||||
|
||||
@Type(() => ModulosOutputDto)
|
||||
@Expose()
|
||||
modulo;
|
||||
|
||||
@Type(() => TipoCarritoOutputDto)
|
||||
@Expose()
|
||||
tipoCarrito;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class Carrito {
|
||||
@Column({ type: String, nullable: false, length: 30 })
|
||||
modelo: string;
|
||||
|
||||
@ManyToOne(() => Modulo, (modulo) => modulo.carritos)
|
||||
@ManyToOne(() => Modulo, (modulo) => modulo.carritos, { eager: true })
|
||||
@JoinColumn({ name: 'id_modulo' })
|
||||
modulo: Modulo;
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { InstitucionesOutputDto } from '../../../institucion/dto/output/instituciones.dto';
|
||||
|
||||
export class ModuloOutputDto {
|
||||
@Expose()
|
||||
activo;
|
||||
|
||||
@Expose()
|
||||
id_modulo;
|
||||
|
||||
@Expose()
|
||||
modulo;
|
||||
|
||||
@Expose()
|
||||
@Type(() => InstitucionesOutputDto)
|
||||
institucion;
|
||||
}
|
||||
Reference in New Issue
Block a user