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