product variant

This commit is contained in:
morteza-mortezai
2025-11-29 10:30:37 +03:30
parent 9f32dff2c0
commit 754496f259
3 changed files with 9 additions and 20 deletions
@@ -1,19 +1,9 @@
import { Expose } from "class-transformer";
import { IsNotEmpty, IsOptional, IsString, Length } from "class-validator";
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
import { ApiProperty } from "../../../common/decorator/swggerDocs";
import { IsValidId } from "../../../common/decorator/validation.decorator";
import { ThemeValueModel } from "../models/themeValue.model";
export class UpdateThemeValueDTO {
@Expose()
@IsNotEmpty()
@IsString()
@Length(24, 24)
@IsValidId(ThemeValueModel)
@ApiProperty({ type: "string", description: "theme value id", example: "66f3bcaee566db722a044c62" })
themeValueId: string;
@Expose()
@IsOptional()
@IsNotEmpty()
+4 -6
View File
@@ -109,10 +109,10 @@ class ThemeService {
};
}
async updateThemeValue(updateDto: UpdateThemeValueDTO) {
if (!isValidObjectId(updateDto.themeValueId)) throw new BadRequestError(CommonMessage.NotValidId);
async updateThemeValue(id: string, updateDto: UpdateThemeValueDTO) {
if (!isValidObjectId(id)) throw new BadRequestError(CommonMessage.NotValidId);
const existingThemeValue = await this.themeValueRepository.findById(updateDto.themeValueId);
const existingThemeValue = await this.themeValueRepository.findById(id);
if (!existingThemeValue) throw new BadRequestError(CommonMessage.NotFoundById);
const updateData: Partial<{ name: string; value: string | number }> = {};
@@ -125,9 +125,7 @@ class ThemeService {
updateData.value = updateDto.value;
}
const updatedThemeValue = await this.themeValueRepository.model
.findByIdAndUpdate(updateDto.themeValueId, updateData, { new: true })
.populate("theme");
const updatedThemeValue = await this.themeValueRepository.model.findByIdAndUpdate(id, updateData, { new: true }).populate("theme");
return {
message: CommonMessage.Updated,