chore: fix problem of transcation beeing commited throw update the "

category variant
This commit is contained in:
mahyargdz
2025-09-21 11:45:24 +03:30
parent 3d1aa01f2e
commit 79f597cc90
23 changed files with 52 additions and 97 deletions
@@ -1,6 +1,7 @@
import { Schema, model } from "mongoose";
import { IDimensions, IPrice, IProductVariant, ISaleFormat, IStatistics } from "./Abstraction/IProductVariant";
import { CategoryThemeEnum } from "../../../common/enums/category.enum";
import { ProductMarketStatus } from "../../../common/enums/product.enum";
const productStatisticsSchema = new Schema<IStatistics>(
@@ -44,6 +45,24 @@ const productPriceSchema = new Schema<IPrice>(
{ _id: false },
);
// Utility function to generate dynamic category theme fields
const generateCategoryThemeFields = () => {
const fields: Record<string, { type: NumberConstructor; ref: string; required: boolean }> = {};
Object.values(CategoryThemeEnum).forEach((theme) => {
if (theme !== CategoryThemeEnum.No_color_No_sized) {
const fieldName = theme.toLowerCase();
fields[fieldName] = {
type: Number,
ref: theme,
required: false,
};
}
});
return fields;
};
const productVariantSchema = new Schema<IProductVariant>(
{
product: { type: Number, ref: "Product", required: true },
@@ -59,9 +78,7 @@ const productVariantSchema = new Schema<IProductVariant>(
saleFormat: { type: productSaleFormat },
dimensions: { type: productDimensionsSchema, required: true },
sellerSpecialCode: { type: String },
color: { type: Number, ref: "Color", required: false },
size: { type: Number, ref: "Size", required: false },
meterage: { type: Number, ref: "Meterage", required: false },
...generateCategoryThemeFields(),
},
{ timestamps: true, toObject: { virtuals: true, versionKey: false }, toJSON: { virtuals: true, versionKey: false }, id: false },
);