(content-manager): types for data mapper service (#18887)

This commit is contained in:
Jamie Howard 2023-12-12 15:47:23 +00:00 committed by GitHub
parent 17801215c6
commit 0d8a6e7cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { pick, getOr } from 'lodash/fp'; import { pick, getOr } from 'lodash/fp';
import { contentTypes as contentTypesUtils } from '@strapi/utils'; import { contentTypes as contentTypesUtils } from '@strapi/utils';
import { Attribute, Schema } from '@strapi/types';
const dtoFields = [ const dtoFields = [
'uid', 'uid',
@ -15,7 +16,7 @@ const dtoFields = [
]; ];
export default () => ({ export default () => ({
toContentManagerModel(contentType: any) { toContentManagerModel(contentType: Schema.Component) {
return { return {
...contentType, ...contentType,
apiID: contentType.modelName, apiID: contentType.modelName,
@ -32,14 +33,14 @@ export default () => ({
toDto: pick(dtoFields), toDto: pick(dtoFields),
}); });
const formatAttributes = (contentType: any) => { const formatAttributes = (contentType: Schema.Component) => {
const { getVisibleAttributes, getTimestamps, getCreatorFields } = contentTypesUtils; const { getVisibleAttributes, getTimestamps, getCreatorFields } = contentTypesUtils;
// only get attributes that can be seen in the auto generated Edit view or List view // only get attributes that can be seen in the auto generated Edit view or List view
return getVisibleAttributes(contentType) return getVisibleAttributes(contentType)
.concat(getTimestamps(contentType)) .concat(getTimestamps(contentType))
.concat(getCreatorFields(contentType)) .concat(getCreatorFields(contentType))
.reduce((acc: any, key: any) => { .reduce((acc: any, key: string) => {
const attribute = contentType.attributes[key]; const attribute = contentType.attributes[key];
// ignore morph until they are handled in the front // ignore morph until they are handled in the front
@ -53,7 +54,7 @@ const formatAttributes = (contentType: any) => {
}; };
// FIXME: not needed // FIXME: not needed
const formatAttribute = (key: any, attribute: any) => { const formatAttribute = (key: any, attribute: Attribute.Any) => {
if (attribute.type === 'relation') { if (attribute.type === 'relation') {
return toRelation(attribute); return toRelation(attribute);
} }
@ -62,14 +63,14 @@ const formatAttribute = (key: any, attribute: any) => {
}; };
// FIXME: not needed // FIXME: not needed
const toRelation = (attribute: any) => { const toRelation = (attribute: Attribute.Relation) => {
return { return {
...attribute, ...attribute,
type: 'relation', type: 'relation',
targetModel: attribute.target, targetModel: 'target' in attribute ? attribute.target : undefined,
relationType: attribute.relation, relationType: attribute.relation,
}; };
}; };
const isVisible = (model: any) => const isVisible = (model: Schema.Component): boolean =>
getOr(true, 'pluginOptions.content-manager.visible', model) === true; getOr(true, 'pluginOptions.content-manager.visible', model) === true;