mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Relational fields - Get mainField from configuration's metadata (#8789)
* Returns the mainField for the list view Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Use lodash fp Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Move helpers functions outside of the controller Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
709602bb72
commit
40b31da75c
@ -1,8 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const { has, assoc, mapValues, prop } = require('lodash/fp');
|
||||
const { getService } = require('../utils');
|
||||
const { createModelConfigurationSchema, validateKind } = require('./validation');
|
||||
|
||||
const hasEditMainField = has('edit.mainField');
|
||||
const getEditMainField = prop('edit.mainField');
|
||||
const assocListMainField = assoc('list.mainField');
|
||||
|
||||
const assocMainField = metadata =>
|
||||
hasEditMainField(metadata) ? assocListMainField(getEditMainField(metadata), metadata) : metadata;
|
||||
|
||||
module.exports = {
|
||||
async findContentTypes(ctx) {
|
||||
const { kind } = ctx.query;
|
||||
@ -31,11 +39,17 @@ module.exports = {
|
||||
}
|
||||
|
||||
const configuration = await contentTypeService.findConfiguration(contentType);
|
||||
|
||||
const confWithUpdatedMetadata = {
|
||||
...configuration,
|
||||
metadatas: mapValues(assocMainField, configuration.metadatas),
|
||||
};
|
||||
|
||||
const components = await contentTypeService.findComponentsConfigurations(contentType);
|
||||
|
||||
ctx.body = {
|
||||
data: {
|
||||
contentType: configuration,
|
||||
contentType: confWithUpdatedMetadata,
|
||||
components,
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user