Lo que hicimios
// src\products\dtos\products.dtos.ts
@IsOptional()
@IsPositive()
minPrice: number;
@ValidateIf((item) => item.minPrice)
@IsPositive()
maxPrice: number;
// src\products\services\products.service.ts
// Cambiamos el servicio
async findAll(params?: FilterProductDto) {
if (params) {
const where: FindConditions<Product> = {};
const { limit, offset } = params;
const { maxPrice, minPrice } = params;
if (minPrice && maxPrice) {
where.price = Between(minPrice, maxPrice);
}
return this.productRepo.find({
relations: ['brand'],
where,
take: limit,
skip: offset,
});
}
return this.productRepo.find({
relations: ['brand'],
});
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.