product variant
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -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