mirror of
https://github.com/hexastack/hexabot
synced 2025-05-11 08:01:39 +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 { ContentTypeService } from './../services/content-type.service';
|
||||||
import { ContentService } from './../services/content.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 { ContentTransformInterceptor } from '../interceptors/content.interceptor';
|
||||||
import { ContentType } from '../schemas/content-type.schema';
|
import { ContentType } from '../schemas/content-type.schema';
|
||||||
import {
|
import {
|
||||||
@ -319,16 +319,12 @@ export class ContentController extends BaseController<
|
|||||||
* @returns The updated content document.
|
* @returns The updated content document.
|
||||||
*/
|
*/
|
||||||
@CsrfCheck(true)
|
@CsrfCheck(true)
|
||||||
@Patch('/:id')
|
@Patch(':id')
|
||||||
async updateOne(
|
async updateOne(
|
||||||
@Body() contentDto: ContentCreateDto,
|
@Body() contentDto: ContentUpdateDto,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
): Promise<Content> {
|
): Promise<Content> {
|
||||||
const contentType = await this.contentTypeService.findOne(
|
const updatedContent = await this.contentService.updateOne(id, contentDto);
|
||||||
contentDto.entity,
|
|
||||||
);
|
|
||||||
const newContent = this.filterDynamicFields(contentDto, contentType);
|
|
||||||
const updatedContent = await this.contentService.updateOne(id, newContent);
|
|
||||||
if (!updatedContent) {
|
if (!updatedContent) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
`Failed to update content with id ${id}. Content not found.`,
|
`Failed to update content with id ${id}. Content not found.`,
|
||||||
|
@ -32,3 +32,15 @@ export class ContentCreateDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
dynamicFields?: Record<string, any>;
|
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 { _csrf, title, status, entity, ...dynamicFields } = content;
|
||||||
const processed: ContentCreateDto & { _csrf?: string } = {
|
const processed: ContentCreateDto & { _csrf?: string } = {
|
||||||
_csrf: _csrf?.toString(),
|
_csrf: _csrf?.toString(),
|
||||||
entity: entity.toString(),
|
entity: entity?.toString(),
|
||||||
status: !!status,
|
status: !!status,
|
||||||
title: title.toString(),
|
title: title?.toString(),
|
||||||
dynamicFields,
|
dynamicFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user