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,
|
||||
|
||||
@@ -564,14 +564,14 @@ class ProductService {
|
||||
// Check if a variant with the same themeValue already exists
|
||||
// const query: FilterQuery<IProductVariant> = { product: product._id };
|
||||
|
||||
// if (addVariantDto.themeValueId) {
|
||||
// const existingVariant = await this.productVariantRepo.model.findOne({
|
||||
// product: product._id,
|
||||
// themeValue: addVariantDto.themeValueId,
|
||||
// });
|
||||
if (addVariantDto.themeValueId) {
|
||||
const existingVariant = await this.productVariantRepo.model.findOne({
|
||||
product: product._id,
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user