mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 01:09:49 +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';
|
'use strict';
|
||||||
|
|
||||||
|
const { has, assoc, mapValues, prop } = require('lodash/fp');
|
||||||
const { getService } = require('../utils');
|
const { getService } = require('../utils');
|
||||||
const { createModelConfigurationSchema, validateKind } = require('./validation');
|
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 = {
|
module.exports = {
|
||||||
async findContentTypes(ctx) {
|
async findContentTypes(ctx) {
|
||||||
const { kind } = ctx.query;
|
const { kind } = ctx.query;
|
||||||
@ -31,11 +39,17 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configuration = await contentTypeService.findConfiguration(contentType);
|
const configuration = await contentTypeService.findConfiguration(contentType);
|
||||||
|
|
||||||
|
const confWithUpdatedMetadata = {
|
||||||
|
...configuration,
|
||||||
|
metadatas: mapValues(assocMainField, configuration.metadatas),
|
||||||
|
};
|
||||||
|
|
||||||
const components = await contentTypeService.findComponentsConfigurations(contentType);
|
const components = await contentTypeService.findComponentsConfigurations(contentType);
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: {
|
data: {
|
||||||
contentType: configuration,
|
contentType: confWithUpdatedMetadata,
|
||||||
components,
|
components,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user