Merge pull request #67 from Danakcorp/mrtz

them valkue
This commit is contained in:
morteza-mortezai
2025-11-29 13:15:40 +03:30
committed by GitHub
3 changed files with 33 additions and 42 deletions
+20
View File
@@ -83,6 +83,22 @@ class SaleFormatDTO {
//################################# //#################################
class ThemeValueDTO {
@Expose()
_id: string;
@Expose()
theme: string;
@Expose()
name?: string;
@Expose()
value: string | number;
}
//#################################
export class ProductDetailVariantDTO { export class ProductDetailVariantDTO {
@Expose() @Expose()
_id: string; _id: string;
@@ -136,6 +152,10 @@ export class ProductDetailVariantDTO {
@Expose() @Expose()
@Type(() => Size_MeterageDTO) @Type(() => Size_MeterageDTO)
meterage?: Size_MeterageDTO; meterage?: Size_MeterageDTO;
@Expose()
@Type(() => ThemeValueDTO)
themeValue?: ThemeValueDTO;
} }
//################################# //#################################
+12 -39
View File
@@ -1320,13 +1320,13 @@ export class ProductRepository extends BaseRepository<IProduct> {
}, },
}, },
}, },
{ // {
$match: { // $match: {
$expr: { // $expr: {
$or: [{ $gt: [{ $size: "$variants" }, 0] }, { $eq: ["$category.theme", "noColor_noSize"] }], // $or: [{ $gt: [{ $size: "$variants" }, 0] }, { $eq: ["$category.theme", "noColor_noSize"] }],
}, // },
}, // },
}, // },
{ {
$unwind: { $unwind: {
path: "$variants", path: "$variants",
@@ -1371,46 +1371,19 @@ export class ProductRepository extends BaseRepository<IProduct> {
}, },
{ {
$lookup: { $lookup: {
from: "colors", from: "themevalues",
localField: "variants.color", localField: "variants.themeValue",
foreignField: "_id", foreignField: "_id",
as: "variants.color", as: "variants.themeValue",
}, },
}, },
{ {
$unwind: { $unwind: {
path: "$variants.color", path: "$variants.themeValue",
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",
preserveNullAndEmptyArrays: true, preserveNullAndEmptyArrays: true,
}, },
}, },
{ {
$group: { $group: {
_id: "$_id", _id: "$_id",
@@ -961,9 +961,7 @@ class ProductService {
async getProductDetails(productId: number) { async getProductDetails(productId: number) {
await this.validateProduct(productId); await this.validateProduct(productId);
const docs = await this.productRepo.getProductDetails(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 product = ProductDTO.transformProduct(docs[0]);
const stats = await this.commentRepo.getProductStats(productId); const stats = await this.commentRepo.getProductStats(productId);
const categoryPath = await this.categoryRepo.getCategoryPath(product.category._id.toString()); const categoryPath = await this.categoryRepo.getCategoryPath(product.category._id.toString());