@@ -82,51 +82,17 @@ class SaleFormatDTO {
|
||||
}
|
||||
|
||||
//#################################
|
||||
|
||||
class VariantProductCategoryDTO {
|
||||
export class ThemeDTO {
|
||||
@Expose()
|
||||
_id: string;
|
||||
|
||||
@Expose()
|
||||
title_fa: string;
|
||||
|
||||
@Expose()
|
||||
theme: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
class VariantProductDTO {
|
||||
@Expose()
|
||||
_id: number;
|
||||
|
||||
@Expose()
|
||||
title_fa: string;
|
||||
|
||||
@Expose()
|
||||
title_en: string;
|
||||
|
||||
@Expose()
|
||||
status: string;
|
||||
|
||||
@Expose()
|
||||
model: string;
|
||||
|
||||
@Expose()
|
||||
@Type(() => ImagesUrlDTO)
|
||||
images: ImagesUrlDTO;
|
||||
|
||||
@Expose()
|
||||
@Type(() => VariantProductCategoryDTO)
|
||||
category: VariantProductCategoryDTO;
|
||||
}
|
||||
|
||||
//#################################
|
||||
|
||||
export class ThemeValueDTO {
|
||||
@Expose()
|
||||
_id: string;
|
||||
|
||||
@Expose()
|
||||
theme: string;
|
||||
theme: ThemeDTO;
|
||||
|
||||
@Expose()
|
||||
name?: string;
|
||||
@@ -331,10 +297,6 @@ export class ProductVariantDTO {
|
||||
@Type(() => ThemeValueDTO)
|
||||
themeValue?: ThemeValueDTO;
|
||||
|
||||
@Expose()
|
||||
@Type(() => VariantProductDTO)
|
||||
product?: VariantProductDTO;
|
||||
|
||||
public static transformProduct(data: IProductVariant): ProductVariantDTO {
|
||||
const productVariantDTO = plainToInstance(ProductVariantDTO, data, {
|
||||
excludeExtraneousValues: true,
|
||||
|
||||
@@ -86,15 +86,36 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
|
||||
{
|
||||
$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,30 +124,7 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
|
||||
as: "shipmentMethod",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$themeValue",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$addFields: {
|
||||
product: {
|
||||
_id: "$product._id",
|
||||
title_fa: "$product.title_fa",
|
||||
title_en: "$product.title_en",
|
||||
status: "$product.status",
|
||||
model: "$product.model",
|
||||
images: "$product.imagesUrl",
|
||||
category: {
|
||||
_id: "$category._id",
|
||||
title_fa: "$category.title_fa",
|
||||
theme: "$category.theme",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$addFields: {
|
||||
@@ -138,7 +136,7 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
|
||||
model: "$product.model",
|
||||
category_theme: "$category.theme",
|
||||
category_title_fa: "$category.title_fa",
|
||||
coverImage: "$product.images.cover",
|
||||
coverImage: "$product.imagesUrl.cover",
|
||||
is_variant_active: {
|
||||
$cond: {
|
||||
if: { $eq: ["$market_status", ProductMarketStatus.Marketable] },
|
||||
@@ -165,6 +163,7 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
|
||||
{
|
||||
$project: {
|
||||
category: 0,
|
||||
product: 0,
|
||||
shop: 0,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user