diff --git a/src/modules/product/DTO/product.dto.ts b/src/modules/product/DTO/product.dto.ts index 1526bb6..20aa784 100644 --- a/src/modules/product/DTO/product.dto.ts +++ b/src/modules/product/DTO/product.dto.ts @@ -83,6 +83,22 @@ class SaleFormatDTO { //################################# +class ThemeValueDTO { + @Expose() + _id: string; + + @Expose() + theme: string; + + @Expose() + name?: string; + + @Expose() + value: string | number; +} + +//################################# + export class ProductDetailVariantDTO { @Expose() _id: string; @@ -136,6 +152,10 @@ export class ProductDetailVariantDTO { @Expose() @Type(() => Size_MeterageDTO) meterage?: Size_MeterageDTO; + + @Expose() + @Type(() => ThemeValueDTO) + themeValue?: ThemeValueDTO; } //################################# diff --git a/src/modules/product/Repository/product.ts b/src/modules/product/Repository/product.ts index a5c6e23..9852dc7 100644 --- a/src/modules/product/Repository/product.ts +++ b/src/modules/product/Repository/product.ts @@ -1320,13 +1320,13 @@ export class ProductRepository extends BaseRepository { }, }, }, - { - $match: { - $expr: { - $or: [{ $gt: [{ $size: "$variants" }, 0] }, { $eq: ["$category.theme", "noColor_noSize"] }], - }, - }, - }, + // { + // $match: { + // $expr: { + // $or: [{ $gt: [{ $size: "$variants" }, 0] }, { $eq: ["$category.theme", "noColor_noSize"] }], + // }, + // }, + // }, { $unwind: { path: "$variants", @@ -1371,46 +1371,19 @@ export class ProductRepository extends BaseRepository { }, { $lookup: { - from: "colors", - localField: "variants.color", + from: "themevalues", + localField: "variants.themeValue", foreignField: "_id", - as: "variants.color", + as: "variants.themeValue", }, }, { $unwind: { - path: "$variants.color", - preserveNullAndEmptyArrays: true, - }, - }, - { - $lookup: { - from: "sizes", - localField: "variants.size", - foreignField: "_id", - as: "variants.size", - }, - }, - { - $unwind: { - path: "$variants.size", - preserveNullAndEmptyArrays: true, - }, - }, - { - $lookup: { - from: "meterages", - localField: "variants.meterage", - foreignField: "_id", - as: "variants.meterage", - }, - }, - { - $unwind: { - path: "$variants.meterage", + path: "$variants.themeValue", preserveNullAndEmptyArrays: true, }, }, + { $group: { _id: "$_id", diff --git a/src/modules/product/providers/product.service.ts b/src/modules/product/providers/product.service.ts index 912d777..5089dc2 100644 --- a/src/modules/product/providers/product.service.ts +++ b/src/modules/product/providers/product.service.ts @@ -961,9 +961,7 @@ class ProductService { async getProductDetails(productId: number) { await this.validateProduct(productId); const docs = await this.productRepo.getProductDetails(productId); - if ((!docs?.[0]?.variants || docs?.[0]?.variants.length === 0) && docs?.[0]?.category.theme !== "noColor_noSize") { - throw new BadRequestError(CommonMessage.NotEnoughVariant); - } + const product = ProductDTO.transformProduct(docs[0]); const stats = await this.commentRepo.getProductStats(productId); const categoryPath = await this.categoryRepo.getCategoryPath(product.category._id.toString());