product variant
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user