From 754496f25961c9612c7de9551237a45f17796996 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 29 Nov 2025 10:30:37 +0330 Subject: [PATCH] product variant --- src/modules/admin/controllers/category.controller.ts | 7 ++++--- src/modules/category/DTO/UpdateThemeValue.dto.ts | 12 +----------- src/modules/category/theme.service.ts | 10 ++++------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/modules/admin/controllers/category.controller.ts b/src/modules/admin/controllers/category.controller.ts index 84253b8..83db058 100644 --- a/src/modules/admin/controllers/category.controller.ts +++ b/src/modules/admin/controllers/category.controller.ts @@ -243,16 +243,17 @@ export class AdminCategoryController extends BaseController { @ApiOperation("Update a theme value ==> need to login as admin") @ApiResponse("theme value updated successfully", HttpStatus.Ok) + @ApiParam("id", "id of the theme value", true) @ApiAuth() @ApiModel(UpdateThemeValueDTO) @httpPut( - "/theme-value", + "/theme-value/:id", Guard.authAdmin(), Guard.checkAdminPermissions([PermissionEnum.ADMIN]), ValidationMiddleware.validateInput(UpdateThemeValueDTO), ) - public async updateThemeValue(@requestBody() updateDto: UpdateThemeValueDTO) { - const data = await this.themeService.updateThemeValue(updateDto); + public async updateThemeValue(@requestParam("id") id: string, @requestBody() updateDto: UpdateThemeValueDTO) { + const data = await this.themeService.updateThemeValue(id, updateDto); return this.response({ data }); } diff --git a/src/modules/category/DTO/UpdateThemeValue.dto.ts b/src/modules/category/DTO/UpdateThemeValue.dto.ts index de0a4ed..23d3787 100644 --- a/src/modules/category/DTO/UpdateThemeValue.dto.ts +++ b/src/modules/category/DTO/UpdateThemeValue.dto.ts @@ -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() diff --git a/src/modules/category/theme.service.ts b/src/modules/category/theme.service.ts index ad193ab..6422724 100644 --- a/src/modules/category/theme.service.ts +++ b/src/modules/category/theme.service.ts @@ -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,