From e3458a3acf78ede4711b0707b9f12dc7650d9bd8 Mon Sep 17 00:00:00 2001 From: Jed Date: Mon, 30 Dec 2024 18:20:08 +0100 Subject: [PATCH] moves getNonVisibleFields out of convert --- modules/@apostrophecms/schema/index.js | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/modules/@apostrophecms/schema/index.js b/modules/@apostrophecms/schema/index.js index 5371f5989e..2b0389b90c 100644 --- a/modules/@apostrophecms/schema/index.js +++ b/modules/@apostrophecms/schema/index.js @@ -654,7 +654,7 @@ module.exports = { return; } - const nonVisibleFields = await getNonVisibleFields({ + const nonVisibleFields = await self.getNonVisibleFields({ req, schema, destination @@ -675,46 +675,45 @@ module.exports = { if (validErrors.length) { throw validErrors; } + }, - async function getNonVisibleFields({ - req, schema, destination, nonVisibleFields = new Set(), fieldPath = '' - }) { - for (const field of schema) { - const curPath = fieldPath ? `${fieldPath}.${field.name}` : field.name; - const isVisible = await self.isVisible(req, schema, destination, field.name); - if (!isVisible) { - nonVisibleFields.add(curPath); - continue; - } - if (!field.schema) { - continue; - } + async getNonVisibleFields({ + req, schema, destination, nonVisibleFields = new Set(), fieldPath = '' + }) { + for (const field of schema) { + const curPath = fieldPath ? `${fieldPath}.${field.name}` : field.name; + const isVisible = await self.isVisible(req, schema, destination, field.name); + if (!isVisible) { + nonVisibleFields.add(curPath); + continue; + } + if (!field.schema) { + continue; + } - // Relationship does not support conditional fields right now - if ([ 'array' /*, 'relationship' */].includes(field.type) && field.schema) { - for (const arrayItem of destination[field.name] || []) { - await getNonVisibleFields({ - req, - schema: field.schema, - destination: arrayItem, - nonVisibleFields, - fieldPath: `${curPath}.${arrayItem._id}` - }); - } - } else if (field.type === 'object') { - await getNonVisibleFields({ + // Relationship does not support conditional fields right now + if ([ 'array' /*, 'relationship' */].includes(field.type) && field.schema) { + for (const arrayItem of destination[field.name] || []) { + await self.getNonVisibleFields({ req, schema: field.schema, - destination: destination[field.name], + destination: arrayItem, nonVisibleFields, - fieldPath: curPath + fieldPath: `${curPath}.${arrayItem._id}` }); } + } else if (field.type === 'object') { + await self.getNonVisibleFields({ + req, + schema: field.schema, + destination: destination[field.name], + nonVisibleFields, + fieldPath: curPath + }); } - - return nonVisibleFields; } + return nonVisibleFields; }, async handleConvertErrors({