product variant

This commit is contained in:
morteza-mortezai
2025-11-29 09:30:12 +03:30
parent 37ecf9f449
commit 6c8de9867a
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);
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);
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 (createDto.parent) {
await this.categoryRepository.model.findByIdAndUpdate(createDto.parent, { leaf: false });
}
//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 {
message: CategoryMessage.Created,