@@ -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;
|
||||
}
|
||||
|
||||
//#################################
|
||||
|
||||
@@ -1320,13 +1320,13 @@ export class ProductRepository extends BaseRepository<IProduct> {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$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<IProduct> {
|
||||
},
|
||||
{
|
||||
$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",
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user