mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
fix: content update
This commit is contained in:
parent
6c02022d16
commit
764bd8c2b6
@ -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<Content> {
|
||||
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.`,
|
||||
|
@ -32,3 +32,15 @@ export class ContentCreateDto {
|
||||
@IsOptional()
|
||||
dynamicFields?: Record<string, any>;
|
||||
}
|
||||
|
||||
export class ContentUpdateDto {
|
||||
@ApiPropertyOptional({ description: 'Content title', type: String })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
title?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Content status', type: Boolean })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
status?: boolean;
|
||||
}
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user