product vriants bug

This commit is contained in:
morteza-mortezai
2025-11-29 15:04:24 +03:30
parent c0b8fd3cbf
commit 1f16897065
14 changed files with 86 additions and 590 deletions
@@ -44,7 +44,7 @@ export class CreateCategoryDTO {
@IsValidId(ThemeModel)
@ApiProperty({
type: "string",
description: "the variation theme of a category ==> should be one of Color/Size/Meterage or noColor_noSize",
description: "the variation theme of a category ==> ",
})
themeId: string;
}
@@ -57,8 +57,7 @@ export class UpdateCategoryDTO {
@IsValidId(ThemeModel)
@ApiProperty({
type: "string",
description: "the variation theme of a category ==> should be one of Color/Size/Meterage or noColor_noSize",
example: "Color",
description: "the variation theme of a category ==> ",
})
themeId: string;
}
+3 -28
View File
@@ -1,42 +1,17 @@
import { Expose, Transform, Type, plainToInstance } from "class-transformer";
import { ThemeValueDTO } from "../../product/DTO/product.dto";
import { ICategory } from "../models/Abstraction/ICategory";
import { ICategoryAttribute } from "../models/Abstraction/ICategoryAttributes";
export class Size_MeterageDTO {
@Expose()
_id: number;
@Expose()
value: string;
}
export class ColorDTO {
@Expose()
_id: number;
@Expose()
name: string;
@Expose()
hexColor: string;
}
export class VariantDTO {
@Expose()
_id: string;
@Expose()
@Type(() => ColorDTO)
@Type(() => ThemeValueDTO)
@Transform(({ value }) => (value && value.length > 0 ? value : undefined) /*, { toClassOnly: true }*/)
colors: ColorDTO[];
@Expose()
@Type(() => Size_MeterageDTO)
@Transform(({ value }) => (value && value.length > 0 ? value : undefined) /*, { toClassOnly: true }*/)
sizes: Size_MeterageDTO[];
@Expose()
@Type(() => Size_MeterageDTO)
@Transform(({ value }) => (value && value.length > 0 ? value : undefined) /*, { toClassOnly: true }*/)
meterages: Size_MeterageDTO[];
themeValues: ThemeValueDTO[];
}
export class CategoryVariantDTO {
@@ -1,34 +1,11 @@
import { PartialType } from "@nestjs/mapped-types";
import { Expose, Type } from "class-transformer";
import { ArrayMinSize, IsHexColor, IsNotEmpty, IsOptional, ValidateNested } from "class-validator";
import { Expose } from "class-transformer";
import { IsOptional } from "class-validator";
import { ApiProperty } from "../../../common/decorator/swggerDocs";
import { IsValidId } from "../../../common/decorator/validation.decorator";
import { ThemeModel } from "../models/theme.model";
export class CreateColorDTO {
@Expose()
@IsNotEmpty()
name: string;
@Expose()
@IsNotEmpty()
@IsHexColor()
hexColor: string;
}
export class CreateSizeDTO {
@Expose()
@IsNotEmpty()
value: string;
}
export class CreateMeterageDTO {
@Expose()
@IsNotEmpty()
value: string;
}
export class CreateCategoryThemeDTO {
@Expose()
@IsOptional()
@@ -38,46 +15,6 @@ export class CreateCategoryThemeDTO {
description: "theme id",
})
themeId?: string;
@Expose()
@IsOptional()
@IsNotEmpty()
@ArrayMinSize(1)
@ValidateNested({ each: true })
@Type(() => CreateColorDTO)
@ApiProperty({
type: "Array",
required: true,
description: "the variation colors of a category theme",
example: [{ name: "مشکی", hexColor: "#000000" }],
})
colors?: CreateColorDTO[];
@Expose()
@IsOptional()
@IsNotEmpty()
@ArrayMinSize(1)
@ValidateNested({ each: true })
@Type(() => CreateSizeDTO)
@ApiProperty({
type: "Array",
description: "the variation sizes of a category theme",
example: [{ value: "M" }, { value: "S" }, { value: "L" }],
})
sizes?: CreateSizeDTO[];
@Expose()
@IsOptional()
@IsNotEmpty()
@ArrayMinSize(1)
@ValidateNested({ each: true })
@Type(() => CreateSizeDTO)
@ApiProperty({
type: "Array",
description: "the variation meterage of a category theme",
example: [{ value: "10" }, { value: "20" }, { value: "50" }],
})
meterages?: CreateMeterageDTO[];
}
export class UpdateCategoryVariantDTO extends PartialType(CreateCategoryThemeDTO) {}
+1 -1
View File
@@ -149,7 +149,7 @@ class CategoryRepository extends BaseRepository<ICategory> {
for (const category of categories) {
if (!category?.theme || !category?.variants.length) continue;
const theme = `${category?.theme}s`.toLowerCase(); // e.g., 'colors', 'sizes', 'meterages'
const theme = `${category?.theme}s`.toLowerCase();
if (!themeVariantsMap.has(theme)) {
themeVariantsMap.set(theme, new Set());
+2 -4
View File
@@ -391,14 +391,12 @@ class CategoryService {
// get category variants
const categoryVariants = await this.categoryRepository.getCategoryVariants(categoryIds);
const colors = categoryVariants?.colors;
const sizes = categoryVariants?.sizes;
const meterages = categoryVariants?.meterages;
const themeValues = categoryVariants?.themeValues;
// fetch products from the category and its children
const { docs, count } = await this.productRepo.getProductsWithCategory(categoryIds, queries, userId);
const products = docs.map((doc: IProduct) => ProductDTO.transformProduct(doc));
const filters = { attributes: catAttributes?.attributes, priceRange, colors, sizes, meterages };
const filters = { attributes: catAttributes?.attributes, priceRange, themeValues };
// fetch category breadcrumb
const breadcrumb = await this.getCategoryBreadcrumb(category._id.toString());