product verity
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
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>(
|
||||
@@ -45,24 +44,6 @@ 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 },
|
||||
@@ -78,7 +59,7 @@ const productVariantSchema = new Schema<IProductVariant>(
|
||||
saleFormat: { type: productSaleFormat },
|
||||
dimensions: { type: productDimensionsSchema, required: true },
|
||||
sellerSpecialCode: { type: String },
|
||||
...generateCategoryThemeFields(),
|
||||
themeValue: { type: Schema.Types.ObjectId, ref: "ThemeValue", required: true },
|
||||
},
|
||||
{ timestamps: true, toObject: { virtuals: true, versionKey: false }, toJSON: { virtuals: true, versionKey: false }, id: false },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user