Skip to content

Commit

Permalink
moves getNonVisibleFields out of convert
Browse files Browse the repository at this point in the history
  • Loading branch information
ValJed committed Dec 30, 2024
1 parent a18f7fc commit e3458a3
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions modules/@apostrophecms/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ module.exports = {
return;
}

const nonVisibleFields = await getNonVisibleFields({
const nonVisibleFields = await self.getNonVisibleFields({
req,
schema,
destination
Expand All @@ -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({
Expand Down

0 comments on commit e3458a3

Please sign in to comment.