Merge pull request #142 from Hexastack/141-issue-unused-filterdynamicfields-method

fix(api): remove unused filterDynamicFields method
This commit is contained in:
Mohamed Marrouchi 2024-10-04 08:18:52 +01:00 committed by GitHub
commit 934730337c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,7 +40,6 @@ import { SearchFilterPipe } from '@/utils/pipes/search-filter.pipe';
import { ContentTypeService } from './../services/content-type.service';
import { ContentService } from './../services/content.service';
import { ContentCreateDto, ContentUpdateDto } from '../dto/content.dto';
import { ContentType } from '../schemas/content-type.schema';
import {
Content,
ContentFull,
@ -65,34 +64,6 @@ export class ContentController extends BaseController<
super(contentService);
}
/**
* Filters and processes dynamic fields in the content DTO based on the associated content type.
* It ensures that only fields matching the content type are passed forward.
*
* @param contentDto - The content DTO containing dynamic fields.
* @param contentType - The content type schema defining valid fields.
*
* @returns The content DTO with filtered dynamic fields.
*/
filterDynamicFields(contentDto: ContentCreateDto, contentType: ContentType) {
if (!contentType) {
this.logger.warn(
`Content type of id ${contentDto.entity}. Content type not found.`,
);
throw new NotFoundException(
`Content type of id ${contentDto.entity} not found`,
);
}
// Filter the fields coming from the request body to correspond to the contentType
const dynamicFields = contentType.fields.reduce((acc, { name }) => {
return name in contentDto.dynamicFields && contentDto.dynamicFields[name]
? { ...acc, [name]: contentDto.dynamicFields[name] }
: acc;
}, {});
return { ...contentDto, dynamicFields };
}
/**
* Creates new content based on the provided DTO, filtering dynamic fields to match
* the associated content type before persisting it.