Merge pull request #66 from Danakcorp/mrtz

product variant
This commit is contained in:
morteza-mortezai
2025-11-29 10:31:43 +03:30
committed by GitHub
3 changed files with 9 additions and 20 deletions
@@ -243,16 +243,17 @@ export class AdminCategoryController extends BaseController {
@ApiOperation("Update a theme value ==> need to login as admin") @ApiOperation("Update a theme value ==> need to login as admin")
@ApiResponse("theme value updated successfully", HttpStatus.Ok) @ApiResponse("theme value updated successfully", HttpStatus.Ok)
@ApiParam("id", "id of the theme value", true)
@ApiAuth() @ApiAuth()
@ApiModel(UpdateThemeValueDTO) @ApiModel(UpdateThemeValueDTO)
@httpPut( @httpPut(
"/theme-value", "/theme-value/:id",
Guard.authAdmin(), Guard.authAdmin(),
Guard.checkAdminPermissions([PermissionEnum.ADMIN]), Guard.checkAdminPermissions([PermissionEnum.ADMIN]),
ValidationMiddleware.validateInput(UpdateThemeValueDTO), ValidationMiddleware.validateInput(UpdateThemeValueDTO),
) )
public async updateThemeValue(@requestBody() updateDto: UpdateThemeValueDTO) { public async updateThemeValue(@requestParam("id") id: string, @requestBody() updateDto: UpdateThemeValueDTO) {
const data = await this.themeService.updateThemeValue(updateDto); const data = await this.themeService.updateThemeValue(id, updateDto);
return this.response({ data }); return this.response({ data });
} }
@@ -1,19 +1,9 @@
import { Expose } from "class-transformer"; 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 { ApiProperty } from "../../../common/decorator/swggerDocs";
import { IsValidId } from "../../../common/decorator/validation.decorator";
import { ThemeValueModel } from "../models/themeValue.model";
export class UpdateThemeValueDTO { export class UpdateThemeValueDTO {
@Expose()
@IsNotEmpty()
@IsString()
@Length(24, 24)
@IsValidId(ThemeValueModel)
@ApiProperty({ type: "string", description: "theme value id", example: "66f3bcaee566db722a044c62" })
themeValueId: string;
@Expose() @Expose()
@IsOptional() @IsOptional()
@IsNotEmpty() @IsNotEmpty()
+4 -6
View File
@@ -109,10 +109,10 @@ class ThemeService {
}; };
} }
async updateThemeValue(updateDto: UpdateThemeValueDTO) { async updateThemeValue(id: string, updateDto: UpdateThemeValueDTO) {
if (!isValidObjectId(updateDto.themeValueId)) throw new BadRequestError(CommonMessage.NotValidId); 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); if (!existingThemeValue) throw new BadRequestError(CommonMessage.NotFoundById);
const updateData: Partial<{ name: string; value: string | number }> = {}; const updateData: Partial<{ name: string; value: string | number }> = {};
@@ -125,9 +125,7 @@ class ThemeService {
updateData.value = updateDto.value; updateData.value = updateDto.value;
} }
const updatedThemeValue = await this.themeValueRepository.model const updatedThemeValue = await this.themeValueRepository.model.findByIdAndUpdate(id, updateData, { new: true }).populate("theme");
.findByIdAndUpdate(updateDto.themeValueId, updateData, { new: true })
.populate("theme");
return { return {
message: CommonMessage.Updated, message: CommonMessage.Updated,