From 6f49c3fc8f2bfc4a04f5872751a6704d160a482f Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 13 Dec 2025 16:37:16 +0330 Subject: [PATCH] pop theme --- src/modules/product/DTO/product.dto.ts | 6 +++- .../product/Repository/productVarinat.ts | 32 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/modules/product/DTO/product.dto.ts b/src/modules/product/DTO/product.dto.ts index 4645f23..66fe230 100644 --- a/src/modules/product/DTO/product.dto.ts +++ b/src/modules/product/DTO/product.dto.ts @@ -82,13 +82,17 @@ class SaleFormatDTO { } //################################# +export class ThemeDTO { + @Expose() + title: string; +} export class ThemeValueDTO { @Expose() _id: string; @Expose() - theme: string; + theme: ThemeDTO; @Expose() name?: string; diff --git a/src/modules/product/Repository/productVarinat.ts b/src/modules/product/Repository/productVarinat.ts index 27a3969..36b6425 100644 --- a/src/modules/product/Repository/productVarinat.ts +++ b/src/modules/product/Repository/productVarinat.ts @@ -86,15 +86,36 @@ export class ProductVariantRepository extends BaseRepository { { $unwind: "$category", }, - { $lookup: { - from: "themeValues", + from: "themevalues", localField: "themeValue", foreignField: "_id", as: "themeValue", }, }, + { + $unwind: { + path: "$themeValue", + preserveNullAndEmptyArrays: true, + }, + }, + { + $lookup: { + from: "themes", + localField: "themeValue.theme", + foreignField: "_id", + as: "theme_doc", + }, + }, + { + $addFields: { + "themeValue.theme": { $arrayElemAt: ["$theme_doc", 0] }, + }, + }, + { + $project: { theme_doc: 0 }, // drop the temporary array + }, { $lookup: { from: "shipments", @@ -103,12 +124,7 @@ export class ProductVariantRepository extends BaseRepository { as: "shipmentMethod", }, }, - { - $unwind: { - path: "$themeValue", - preserveNullAndEmptyArrays: true, - }, - }, + { $addFields: {