Merge pull request #64 from Danakcorp/mrtz

product variant
This commit is contained in:
morteza-mortezai
2025-11-29 09:36:55 +03:30
committed by GitHub
2 changed files with 15 additions and 12 deletions
+8 -5
View File
@@ -127,17 +127,20 @@ class CategoryService {
createDto.title_en = slugify(createDto.title_en); createDto.title_en = slugify(createDto.title_en);
const existTitle = await this.categoryRepository.findByTitle(createDto.title_en); const existTitle = await this.categoryRepository.findByTitle(createDto.title_en);
const theme = await this.themeRepo.findById(createDto.themeId);
if (!theme) throw new BadRequestError(CommonMessage.NotFoundById);
if (existTitle) throw new BadRequestError(CategoryMessage.DuplicateTitle); if (existTitle) throw new BadRequestError(CategoryMessage.DuplicateTitle);
let themeIdOrNull: any = null;
if (createDto.themeId) {
const themeDoc = await this.themeRepo.findById(createDto.themeId);
if (!themeDoc) throw new BadRequestError(CommonMessage.NotFoundById);
themeIdOrNull = themeDoc._id;
}
//if parent exist first set parent leaf false //if parent exist first set parent leaf false
if (createDto.parent) { if (createDto.parent) {
await this.categoryRepository.model.findByIdAndUpdate(createDto.parent, { leaf: false }); await this.categoryRepository.model.findByIdAndUpdate(createDto.parent, { leaf: false });
} }
//we set the leaf to true //we set the leaf to true
const category = await this.categoryRepository.model.create({ ...createDto, theme: theme._id }); const category = await this.categoryRepository.model.create({ ...createDto, theme: themeIdOrNull });
return { return {
message: CategoryMessage.Created, message: CategoryMessage.Created,
@@ -564,14 +564,14 @@ class ProductService {
// Check if a variant with the same themeValue already exists // Check if a variant with the same themeValue already exists
// const query: FilterQuery<IProductVariant> = { product: product._id }; // const query: FilterQuery<IProductVariant> = { product: product._id };
// if (addVariantDto.themeValueId) { if (addVariantDto.themeValueId) {
// const existingVariant = await this.productVariantRepo.model.findOne({ const existingVariant = await this.productVariantRepo.model.findOne({
// product: product._id, product: product._id,
// themeValue: addVariantDto.themeValueId, themeValue: addVariantDto.themeValueId,
// }); });
// if (existingVariant) throw new BadRequestError(ProductMessage.VariantAlreadyExists); if (existingVariant) throw new BadRequestError(ProductMessage.VariantAlreadyExists);
// } }
const productVariant = await this.createProductVariant(addVariantDto, product._id, shop._id.toString(), session); const productVariant = await this.createProductVariant(addVariantDto, product._id, shop._id.toString(), session);