diff --git a/api/src/cms/controllers/content.controller.ts b/api/src/cms/controllers/content.controller.ts index ff2e52e..4b2b6e6 100644 --- a/api/src/cms/controllers/content.controller.ts +++ b/api/src/cms/controllers/content.controller.ts @@ -39,7 +39,7 @@ import { SearchFilterPipe } from '@/utils/pipes/search-filter.pipe'; import { ContentTypeService } from './../services/content-type.service'; import { ContentService } from './../services/content.service'; -import { ContentCreateDto } from '../dto/content.dto'; +import { ContentCreateDto, ContentUpdateDto } from '../dto/content.dto'; import { ContentTransformInterceptor } from '../interceptors/content.interceptor'; import { ContentType } from '../schemas/content-type.schema'; import { @@ -319,16 +319,12 @@ export class ContentController extends BaseController< * @returns The updated content document. */ @CsrfCheck(true) - @Patch('/:id') + @Patch(':id') async updateOne( - @Body() contentDto: ContentCreateDto, + @Body() contentDto: ContentUpdateDto, @Param('id') id: string, ): Promise { - const contentType = await this.contentTypeService.findOne( - contentDto.entity, - ); - const newContent = this.filterDynamicFields(contentDto, contentType); - const updatedContent = await this.contentService.updateOne(id, newContent); + const updatedContent = await this.contentService.updateOne(id, contentDto); if (!updatedContent) { this.logger.warn( `Failed to update content with id ${id}. Content not found.`, diff --git a/api/src/cms/dto/content.dto.ts b/api/src/cms/dto/content.dto.ts index b77de0c..1981bc2 100644 --- a/api/src/cms/dto/content.dto.ts +++ b/api/src/cms/dto/content.dto.ts @@ -32,3 +32,15 @@ export class ContentCreateDto { @IsOptional() dynamicFields?: Record; } + +export class ContentUpdateDto { + @ApiPropertyOptional({ description: 'Content title', type: String }) + @IsString() + @IsOptional() + title?: string; + + @ApiPropertyOptional({ description: 'Content status', type: Boolean }) + @IsBoolean() + @IsOptional() + status?: boolean; +} diff --git a/api/src/cms/utilities/index.ts b/api/src/cms/utilities/index.ts index 8fa950e..1459fa6 100644 --- a/api/src/cms/utilities/index.ts +++ b/api/src/cms/utilities/index.ts @@ -14,9 +14,9 @@ export const preprocessDynamicFields = ( const { _csrf, title, status, entity, ...dynamicFields } = content; const processed: ContentCreateDto & { _csrf?: string } = { _csrf: _csrf?.toString(), - entity: entity.toString(), + entity: entity?.toString(), status: !!status, - title: title.toString(), + title: title?.toString(), dynamicFields, };